Write UTF-8 output files with Out-File -Encoding utf8

Why your redirected PowerShell output opens as garbled text in Linux tools — the forgotten encoding parameter.

WindowsFilesencodingpowershellLow risk
Pipe to Out-File -Encoding utf8 to control the file encoding instead of relying on the redirect operator's default.

01Command

Command
$ Get-ChildItem C:\Reports | Out-File -FilePath 'C:\Temp\list.txt' -Encoding utf8

02What it does

In Windows PowerShell 5.1, '>' and Out-File default to UTF-16 LE ('unicode'), which other tools often can't read; explicit -Encoding utf8 fixes that. PowerShell 7 changed the default to utf8NoBOM, which is why the same script behaves differently on different machines. Other useful values: ascii for legacy systems, utf8NoBOM for Linux-friendly output, and oem for console codepage.

03Risk

RiskLow risk
RequirementsPowerShell
!Warning: -Encoding utf8 in Windows PowerShell 5.1 writes a BOM; some Unix tools choke on it — use utf8NoBOM in PowerShell 7 or .NET's [IO.File]::WriteAllLines if the BOM must go.

04Undo

Undo
$ Remove-Item 'C:\Temp\list.txt'

05Sources

  • Out-File | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    Evidence: Microsoft documents Out-File -Encoding with values including utf8, utf8NoBOM, ascii, and unicode, and notes the default encoding differs between Windows PowerShell and PowerShell 7.
  • Out-File - PowerShell
    SS64 · technical · 2026-09-17
    Evidence: SS64 lists the -Encoding parameter values and explains that '>' in PowerShell is an alias for Out-File.

Last verified: 2026-09-17 · Category: Files & Folders

06Related solutions