Using PowerShell to write a file in UTF-8 without the BOM


SUBMITTED BY: Guest

DATE: Nov. 14, 2013, 7:01 a.m.

FORMAT: Text only

SIZE: 318 Bytes

HITS: 1443

  1. Using PowerShell to write a file in UTF-8 without the BOM
  2. $MyFile = Get-Content $MyPath
  3. $MyFile | Out-File -Encoding "UTF8" $MyPath
  4. $MyFile = Get-Content $MyPath
  5. $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding($False)
  6. [System.IO.File]::WriteAllLines($MyPath, $MyFile, $Utf8NoBomEncoding)

comments powered by Disqus