1

I need to generate a txt file in UTF8 without BOM. I started with:

"Text" | Out-File .\File.txt

which gives me UTF-16 LE encoding.

I tried

"Text" | Out-File .\File.txt -Encoding utf8

which gives me UTF-8 with BOM.

How do I get it without BOM?

mklement0
  • 382,024
  • 64
  • 607
  • 775
Christopher Cass
  • 817
  • 4
  • 19
  • 31
  • 1
    In short: In _Windows PowerShell_, creating BOM-less UTF-8 files requires _workarounds_ - either via `New-Item` or via direct use of .NET APIs (fortunately, [_PowerShell (Core) 7+_](https://github.com/PowerShell/PowerShell/blob/master/README.md) now - consistently - _defaults_ to BOM-less UTF-8). See the linked duplicate for details. – mklement0 May 19 '23 at 22:35
  • Glad to hear it, Christopher. – mklement0 May 22 '23 at 16:38

0 Answers0