Powershell and UTF-8

Hi,

long time to updates so I thought I put up a workaround for UTF-8 issues with textfiles and powershell up.

As the German Language has umlauts… äöü … and several other languages too, people will stumble again and again on issues with how to handle those.

This is a problem in a lot of programming languages especially if you have different OS and language versions / settings.

I had the issue that even when a file was saved in UTF-8 the powershell script wouldn’t process the file correctly.

To make matters worse, the file was created in powershell 😦

So the solution I found was quite easy:

$rand = Get-Random
get-content $csv | out-file -encoding utf8 $fileLocation\temp-$rand.csv
$stuff = Import-Csv $fileLocation\temp-$rand.csv -UseCulture -Encoding UTF8
Remove-Item $fileLocation\temp-$rand.csv

This will make UTF-8 work for me.

BTW: The original file was created by:

Export-Csv “somefilename” -NoTypeInformation -UseCulture -Encoding UTF8