Upon executing Confluence REST API calls I get back a response encoded in UTF-8. However, when I export the results with either Out-File or Export-CSV even with the -Encoding utf8 parameter German Umlauts are not correctly represented. For example, 'ü' is still 'ü'.
From what I could gather it's due to the fact that PowerShell 5.1 natively relies on Windows-1252. I verified that Umlauts are preserved when using PowerShell Core by executing[psobject].Assembly.GetTypes() | Where-Object { $_.Name -eq 'ClrFacade'} |
ForEach-Object {
$_.GetMethod('GetDefaultEncoding', [System.Reflection.BindingFlags]'nonpublic,static').Invoke($null, @())
}
Even changing the script file itself to use the encoding UTF-8 with BOM or Windows-1252 does not preserve Umlauts, neither in the PowerShell nor exportet output.
Do you know of any way to tell PowerShell 5.1 to preserve Umlauts while executing the REST call?
I cannot use PowerShell core as further operations require cmdlets which do net yet exist for PowerShell Core.
Thanks!
-Outfileparameter? - AdminOfThings"ü" | out-file c:\temp\umlaut-utf8.txt -encoding utf8i get a file with the bytes "EF BB BF C3 BC 0D 0A" which shows "ü" in notepad, but "ü" in a hex editor. - mclayton"ü" | out-fileworks because it's not first "internalized" by the shell as when executing a cmdlet. So to generalize, each Umlaut that is processed by a cmdlet in PS 5.1. should exhibit the encoding issue. - colonel_claypoo$xmldoc = Invoke-RestMethod -Uri "https://en.wikipedia.org/wiki/%C3%9C"; $xmldoc.DocumentElement.InnerText | out-file c:\temp\out.txt -Encoding utf8;- mclayton