Set the encoding to ANSI in PowerShell 2.0

后端 未结 2 572
春和景丽
春和景丽 2021-01-21 04:17

I want to set the encoding of a file to ANSI using the parameter -Encoding of the Set-Content cmdlet, I tried this one but it didn\'t work:

<         


        
2条回答
  •  星月不相逢
    2021-01-21 04:43

    I use the .NET WriteAllText function for that:

    [IO.File]::WriteAllText($filePath, (Get-Content $filePath))
    

    Ensure the default encoding reflects your desired output using:

    [System.Text.Encoding]::Default
    

    Otherwise, add the enum with the desired encoding as the third parameter.

提交回复
热议问题