Set PowerShell CSV export encoding
How Export-Csv chooses an encoding in Windows PowerShell 5.1 and PowerShell 7, how to write UTF-8 with or without a BOM, what -Encoding Unicode really means, and how to check the result.
Export-Csv turns PowerShell objects into comma-separated or other delimited text. Its -Encoding parameter decides which bytes on disk represent each character. If you pick the wrong encoding, accented letters, non-Latin scripts and emoji can turn into question marks or garbled sequences. The default encoding differs between Windows PowerShell 5.1 and PowerShell 7, which is the most common source of surprises.
Short recommendation
In PowerShell 7, the default (UTF-8 without a byte order mark) suits most uses and preserves every character. Add -Encoding utf8BOM when the file goes to a program that relies on a BOM to recognize UTF-8. In Windows PowerShell 5.1, always pass -Encoding UTF8, because the default there is ASCII and it silently replaces non-ASCII characters. The main tradeoff is the BOM itself: it helps some spreadsheet and Windows tools detect UTF-8, but some parsers and Unix-style tools treat those three bytes as part of the first header name. A legacy single-byte encoding or plain ASCII is preferable only when the receiving system explicitly requires it and the data is known to fit inside it.
What the Encoding parameter actually changes
Encoding changes only the stored bytes. It does not change the characters, fonts or appearance. Inside PowerShell, text is held as .NET strings, and -Encoding controls how those strings are written to the file. Garbled output after export has one of two causes. Either the bytes are correct but the reader decoded them with the wrong encoding, which you can fix by reopening the file with the right setting. Or the export used an encoding that cannot represent the characters, such as ASCII, and the original characters were replaced and are permanently lost. Telling these two cases apart decides whether you need to re-export the file or only reopen it.
The word "Unicode" is ambiguous here. In PowerShell, -Encoding Unicode means UTF-16 little-endian with a BOM, not UTF-8. Every character takes at least two bytes, and many CSV consumers expect UTF-8 or a single-byte code page instead. People searching for a Unicode-safe export usually want UTF-8, which also covers the full Unicode character set.
Defaults by version
| Version | Export-Csv default | What -Encoding UTF8 writes | UTF-8 without BOM |
| Windows PowerShell 5.1 | ASCII (non-ASCII characters become ?) | UTF-8 with BOM | Not available through -Encoding |
| PowerShell 7.x | utf8NoBOM | UTF-8 without BOM | Default; also selectable as utf8NoBOM |
Check which version runs your script with $PSVersionTable.PSVersion. Both versions can be installed side by side: powershell.exe is Windows PowerShell 5.1 and pwsh is PowerShell 7. A scheduled task or automation host may run a different version from the console you tested in, so the same script can produce different bytes.
Commands for common targets
# PowerShell 7: UTF-8 without BOM (same as the default)
$data | Export-Csv -Path report.csv -NoTypeInformation -Encoding utf8
# PowerShell 7: UTF-8 with BOM
$data | Export-Csv -Path report.csv -NoTypeInformation -Encoding utf8BOM
# Windows PowerShell 5.1: UTF-8 (always writes a BOM)
$data | Export-Csv -Path report.csv -NoTypeInformation -Encoding UTF8
# Tab-separated output with explicit encoding
$data | Export-Csv -Path report.tsv -Delimiter "`t" -NoTypeInformation -Encoding utf8
In PowerShell 7, -NoTypeInformation is already the default. Including it does no harm and keeps the script consistent across versions. PowerShell 7 also accepts registered code page names or numbers, such as windows-1252, for a legacy system that requires a specific single-byte encoding. Characters outside that code page cannot be stored, so use this option only when the receiving system demands it.
UTF-8 without a BOM in Windows PowerShell 5.1
Windows PowerShell 5.1 cannot write BOM-less UTF-8 through -Encoding. The workaround is to convert the objects to CSV lines and write them with a .NET encoding object. Pass a full path, because .NET resolves relative paths against the process working directory, which can differ from the current PowerShell location.
$lines = $data | ConvertTo-Csv -NoTypeInformation
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
$path = Join-Path $PWD.Path 'report.csv'
[System.IO.File]::WriteAllLines($path, $lines, $utf8NoBom)
Making a choice the default
$PSDefaultParameterValues sets a session-wide default for the parameter. Put the line in your profile to make it persistent for your own sessions. Shared scripts do not inherit your profile, so scripts that run on other machines or under service accounts should still pass -Encoding explicitly.
$PSDefaultParameterValues['Export-Csv:Encoding'] = 'utf8'
When using -Append, pass the same encoding the file was originally written with. A file that mixes encodings cannot be decoded consistently by any reader.
Will the file stay readable after it is shared?
A CSV file does not declare its encoding, apart from an optional BOM, so the receiving program must either guess or be told. Copying, emailing or uploading the file normally keeps the bytes intact. Copying the text through the clipboard re-encodes it according to the source and destination programs. Import tools in databases, BI products and web uploaders may assume a particular encoding unless you set one, so check their import options.
Excel is the destination most often mentioned. It is widely reported that double-clicking a BOM-less UTF-8 CSV can make Excel decode it with the system's legacy code page, while a file with a BOM is read as UTF-8. Excel's text import options also let you choose the encoding manually. This behavior can vary with Excel version and regional settings, and no test was performed for this article. Confirm it with your own Excel version, using a file that contains the characters you actually need.
Once a file is decoded correctly, the encoding has no effect on reading order or on how assistive technology presents the text. Mis-decoded text is a different matter: screen readers read it out as nonsense, and search, sorting and filtering fail on the affected values. A BOM that a parser does not strip can make the first header appear under a different name, so lookups by column name fail. Import-Csv handles the BOM, but other tools may not.
Quick check before relying on the output
- Add a test row containing accented Latin letters, a non-Latin script and an emoji, then export it.
- Inspect the first bytes with Format-Hex -Path report.csv | Select-Object -First 1. EF BB BF indicates a UTF-8 BOM, FF FE indicates UTF-16 little-endian (PowerShell's Unicode), and neither suggests BOM-less UTF-8 or a single-byte encoding.
- Re-import the file with Import-Csv -Encoding set to the value you exported with, and compare the values to the source data.
- Open the file in the real destination program and confirm the test characters and the first column header appear correctly.
Gaps and uncertainty
No subject-specific measurements or test results were supplied for this article. The statements above describe documented PowerShell behavior. How a particular destination program treats a BOM, or which encoding it assumes, depends on its version and settings, and you should confirm it with a scoped test. The list of accepted -Encoding values has changed across PowerShell releases. To see the values your installed version supports, run Get-Help Export-Csv -Parameter Encoding.