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
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:
in Windows PowerShell:
in PowerShell (Core) 7+, which you're using,
Defaultnow refers to UTF-8, so more work is needed:In PowerShell v7.3-:
In PowerShell v7.4+:[1]
Default character encodings in the two PowerShell editions:
Windows PowerShell, the legacy, Windows-only, ships-with-Windows edition (whose latest and last version is v5.1.x), defaults to the active ANSI code page in key areas - notably
Get-Content/Set-Contentand when the PowerShell engine reads source code - but the defaults vary widely across the built-in cmdlets; case in point:Import-Csvdefaults to UTF-8; see the bottom section of this answer for an overview.PowerShell (Core), the modern, install-on-demand, cross-platform edition (which started with v6 and is currently at v7.2.x), now fortunately consistently defaults to (BOM-less) UTF-8.
[1] The absence of an
Ansi-Encodingvalue in earlier PowerShell (Core) versions was a curious omission, given that anOemvalue (for the active OEM code page) has always existed - see GitHub issue #6562 for the backstory.