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

前端 未结 13 1118
名媛妹妹
名媛妹妹 2020-11-22 06:25

Out-File seems to force the BOM when using UTF-8:

$MyFile = Get-Content $MyPath
$MyFile | Out-File -Encoding \"UTF8\" $MyPath

相关标签:
13条回答
  • 2020-11-22 07:23

    The proper way as of now is to use a solution recommended by @Roman Kuzmin in comments to @M. Dudley answer:

    [IO.File]::WriteAllLines($filename, $content)
    

    (I've also shortened it a bit by stripping unnecessary System namespace clarification - it will be substituted automatically by default.)

    0 讨论(0)
提交回复
热议问题