I was able to convert XML to CSV by using the following code:
#read from file
[xml]$inputFile = Get-Content \"c:\\pstest\\test.xml\"
#export xml as csv
The first object (or Select-Object etc.) in a pipeline defines the header for output no matter if it's file or console output.
What you could do is convert them to csv in two rounds and add it to the same file. Ex:
$inputFile.Transaction.TXNHEAD | ConvertTo-Csv -NoTypeInformation -Delimiter ";" | Set-Content -Path "c:\pstest\test.csv" -Encoding UTF8
$inputFile.Transaction.TXNDETAIL | ConvertTo-Csv -NoTypeInformation -Delimiter ";" | Add-Content -Path "c:\pstest\test.csv" -Encoding UTF8
You can also combine them like this:
$inputFile.Transaction.TXNHEAD, $x.Transaction.TXNDETAIL |
ForEach-Object { $_ | ConvertTo-Csv -NoTypeInformation -Delimiter ";" } |
Set-Content -Path "c:\pstest\test.csv" -Encoding UTF8