Notepad++ says the CSV file is Ansi encoded.
The Powershell 7 Import-CSV commandlet has various -Encoding options but ‘Ansi’ is not one of them.
How do I get Powershell to read this CSV without mangling it?
The options for -Encoding are:
- ascii
- bigendianunicode
- bigendianutf32
- oem
- unicode
- utf7
- utf8
- utf8BOM
- utf8NoBOM
- utf32
>Solution :
To use ANSI encoding, i.e. the code page implied by the active legacy system locale (language for non-Unicode programs):
-
in Windows PowerShell:
-Encoding Default -
in PowerShell (Core) 7+, which you’re using,
Defaultnow refers to UTF-8, so more work is needed:-Encoding ([cultureinfo]::CurrentCulture.TextInfo.ANSICodePage)
The absence of an Ansi -Encoding value in PowerShell (Core) 7+ is a curious omission, given that an Oem value (for the active OEM code page) does exist – see GitHub issue #6562 for a discussion.