powershellpowershell-7.2

Powershell - how to read Ansi CSV file


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:


Solution

  • To use ANSI encoding, i.e. the specific code page implied by the active legacy system locale (language for non-Unicode programs), such as Windows-1252:


    Default character encodings in the two PowerShell editions:


    [1] The absence of an Ansi -Encoding value in earlier PowerShell (Core) versions was a curious omission, given that an Oem value (for the active OEM code page) has always existed - see GitHub issue #6562 for the backstory.