Using PowerShell to write a file in UTF-8


SUBMITTED BY: Guest

DATE: Dec. 12, 2013, 1:49 a.m.

FORMAT: Text only

SIZE: 322 Bytes

HITS: 19659

  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