Byte Order Mark (BOM) is problematic in many programming languages. For example, in Racket. Python also has the same behavior. .NET IO functions can correctly handle BOM.

To ease the pain, one way is to ask your editor not to write BOM. Another way would be to use a command line tool to strip it out. NPM has a strip-bom-cli package. However, in PowerShell, both stdout redirection and out-file forces BOM for UTF8 encoding.

It turns out there's an easy way to strip BOM directly in PowerShell, without any 3rd party tools, by using [IO.File]::WriteAllLines(). For example, to strip BOM for all files under a directory, do:

PS> ls *.cs | %{ $ls = (Get-Content $_); [IO.File]::WriteAllLines($_, $ls) }