Reputation: 11
I'm trying to output a bunch of data and have some of the german Umlauts: ä, ö, ü,.. I was adding -Encoding UTF8 at the end of Export-Csv, but it does not really work. My code:
For ($i = 0; $i -lt $accFileCont.Length; $i++) {
$accFileCont[$i] | Export-Csv $outAccFile -NoTypeInformation -Encoding UTF8
}
I'm expecting ä, ö, ü... instead of "ä",... What is wrong here? It does not output the Umlauts. Thanks in advance :)
Upvotes: 1
Views: 12371
Reputation: 31
For me, it was actually the "-Encoding utf8BOM" which did the job
Environment: Windows 10 20H2 German, German Excel Version, PowerShell 7
My German Excel is not showing the "umlauts" correct, if I am not using utf8BOM.
There is a whole discussion about UTF8 with or without BOM
Actually "Marius" wrote the following comment: "It might not be recommended but it did wonders to my powershell script when trying to output "æøå""
The "C:\sources\new_18.json" is formatted in UTF-8 (it's a simple JSON File)
The "-Delimiter ";"" is for German Excel
$TestVariable = (Get-Content -raw -Encoding UTF8 "C:\sources\new_18.json") | ConvertFrom-Json
$TestVariable.value | Export-Csv "C:\sources\PSOutput\Output_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv" -NoTypeInformation -Delimiter ";" -Encoding utf8BOM
For PowerShell 5: Change "-Encoding utf8BOM" to "-Encoding utf8" (In Powershell 5 "Export-Csv -Encoding utf8" saves documents in utf8BOM")
Upvotes: 3