Context:
- You use PowerShell 2.0 (Windows 7 or Windows Server 2008 R2).
- You want to read CSV file that contain non-ASCII characters.
Problem:
In PowerShell 2.0, Import-Csv
cmdlet doesn’t have -Encoding
option.
Solution:
If you want to read a CSV file without CRLF in cells, you can use Get-Content -Encoding
and ConvertFrom-Csv
like:
PS > Get-Content -Encoding UTF8 ./foobar.csv | ConvertFrom-Csv
If you want to read a CSV file with CRLF in cells, you should convert the CSV file to UTF-16 with BOM, and read the file with Import-Csv
(Import-Csv
can recognize UTF-16 encoding automatically even in PowerShell 2.0):
PS > Get-Content -Encoding UTF8 ./foobar.csv | Out-File -Encoding Unicode -Path "./foobar-utf16.csv" PS > Import-Csv ./foobar-utf16.csv