Set CSV export encoding in PowerShell
How Export-Csv handles encoding in Windows PowerShell 5.1 and PowerShell 7, what 'Unicode' and 'UTF8' really mean, and how to choose and check your export.
Export-Csv turns PowerShell objects into comma-separated text, and its -Encoding parameter decides how that text becomes bytes on disk. The right choice depends on which PowerShell version you run and which program will open the file. The confusing part is that the same parameter value can mean different things in different versions, and the word 'Unicode' does not mean what many people expect.
Short recommendation
For most exports that contain non-English characters, choose UTF-8 and state it explicitly instead of relying on the default. Add a byte order mark (BOM) when the file is headed for Microsoft Excel by double-click, because Excel is widely reported to rely on the BOM to recognize UTF-8. Omit the BOM when the file feeds scripts, databases, Linux tools or web services, since some of those treat the BOM as part of the first column name. Plain ASCII is preferable only when you have confirmed that every value is basic English letters, digits and punctuation, and the receiving system requires ASCII.
What the encoding setting actually changes
Encoding does not restyle, reorder or reverse anything. The characters in your data stay the same in memory; the setting only controls how those characters are written as bytes. That makes it different from visual tricks such as mirrored text or Unicode 'fonts': nothing about the appearance is intended to change. The risk is that a reader decodes the bytes with the wrong rule, which produces garbled text (for example, an accented letter showing up as two odd symbols).
There is one exception where the stored content itself changes: lossy encodings. If you export with ASCII, any character outside the ASCII range is replaced, typically with a question mark. That replacement is written into the file and cannot be undone by reopening it with a different encoding. The same applies to legacy single-byte code pages for characters they cannot represent.
'Unicode' and 'UTF8' in PowerShell terms
In PowerShell, the value Unicode means UTF-16 little-endian, not 'any Unicode-capable encoding'. A file exported with -Encoding Unicode stores most characters in two bytes and starts with the bytes FF FE. Many people searching for a 'Unicode CSV' actually want UTF-8, which is also a Unicode encoding but is far more common for CSV interchange.
The value UTF8 also changed meaning between versions. In Windows PowerShell 5.1 it writes UTF-8 with a BOM. In PowerShell 7 it writes UTF-8 without a BOM, and separate values utf8BOM and utf8NoBOM let you choose explicitly.
| Behavior | Windows PowerShell 5.1 | PowerShell 7 |
| Default encoding for Export-Csv | ASCII (non-ASCII characters are lost) | UTF-8 without BOM |
| -Encoding UTF8 | UTF-8 with BOM | UTF-8 without BOM |
| Explicit BOM choice | Not available as a separate value | utf8BOM or utf8NoBOM |
| -Encoding Unicode | UTF-16 LE with BOM | UTF-16 LE with BOM |
| #TYPE header line by default | Yes, unless -NoTypeInformation is used | No |
Because the default and the meaning of UTF8 both differ, a script that works correctly on one version can produce a different file on the other. Naming the encoding explicitly and checking which version runs the script avoids most surprises.
Common export commands
UTF-8 with BOM, suited to Excel, in Windows PowerShell 5.1:
Get-Process | Select-Object Name, Id |
Export-Csv -Path .\processes.csv -NoTypeInformation -Encoding UTF8
The same intent in PowerShell 7, where the BOM must be requested by name:
Get-Process | Select-Object Name, Id |
Export-Csv -Path ./processes.csv -Encoding utf8BOM
UTF-8 without BOM in PowerShell 7, suited to scripts and non-Windows tools:
$data | Export-Csv -Path ./data.csv -Encoding utf8NoBOM
Windows PowerShell 5.1 has no built-in Export-Csv value for UTF-8 without a BOM. A common workaround is to convert to CSV text and write it through .NET with an encoding object that disables the BOM. Use a full path, because .NET resolves relative paths against the process working directory, which may differ from your PowerShell location.
$csv = $data | ConvertTo-Csv -NoTypeInformation
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllLines('C:\exports\data.csv', $csv, $utf8NoBom)
Tab-separated output uses the same encoding options; only the delimiter changes:
$data | Export-Csv -Path ./data.tsv -Delimiter "`t" -Encoding utf8BOM
To apply one encoding to every Export-Csv call in a session or profile, set a default parameter value. This is convenient but hides the choice from anyone reading an individual script, so an explicit parameter is clearer in shared code.
$PSDefaultParameterValues['Export-Csv:Encoding'] = 'utf8'
Checking what was written
The first bytes of a file show whether a BOM is present. EF BB BF indicates UTF-8 with BOM, FF FE indicates UTF-16 little-endian, and anything else (such as the bytes of your first header letter) suggests no BOM. This check works in both versions:
[System.IO.File]::ReadAllBytes('C:\exports\data.csv')[0..2] |
ForEach-Object { '{0:X2}' -f $_ }
A missing BOM does not prove the file is not UTF-8; it only means a reader must guess or be told. To confirm content survived, include a row with characters you care about, such as accented letters, non-Latin script or an emoji, and inspect it in the actual destination program.
Will the file stay readable after sharing?
Readability depends on the receiving program, not on PowerShell. Keep these points in mind:
- Excel: opening a UTF-8 file without a BOM by double-click is commonly reported to show garbled non-ASCII text, while a BOM usually lets Excel detect UTF-8. Importing through Excel's data import feature lets you pick the encoding manually. Behavior can vary by Excel version and platform, so test with your own copy.
- UTF-16 (the PowerShell Unicode value): preserves every character, but some tools handle it poorly, and spreadsheet programs may interpret delimiters differently for UTF-16 text. Verify before choosing it for CSV.
- Scripts and parsers: some tools read a UTF-8 BOM as invisible characters glued to the first header, so a column named Name becomes unreachable by that name. Python, for example, needs the utf-8-sig codec to strip it.
- Appending: Export-Csv -Append to a file created with a different encoding can mix encodings in one file. Use the same encoding for every write.
- Regional delimiters: in locales where Excel expects semicolons, -UseCulture or an explicit -Delimiter matters as much as encoding for a file that opens cleanly.
On accessibility, encoding itself is neutral: a correctly decoded file presents ordinary text to screen readers, search and editing tools. Garbled text from a mismatched decode is unreadable to people and assistive technology alike, and lost characters from an ASCII export cannot be recovered. No destination-specific accessibility testing was available for this article, so if a file must work with a particular screen reader or system, test it there.
When to keep it plain
If a receiving system documents a required encoding, follow it exactly, even if that means a legacy code page; such a choice can lose characters, so check whether your data fits it. If you cannot confirm the destination, UTF-8 is the safest general format, with the BOM decision based on whether people (Excel) or programs will read it first. When both audiences matter, exporting two copies, one with BOM and one without, is often simpler than finding a single compromise.
Gaps in this review
The behavior described here reflects documented PowerShell parameter behavior and widely known conventions. No measurements or hands-on tests of specific Excel builds, operating systems, parsers or assistive technologies were available. Confirm results in the exact environment where your CSV will be used.