Set the encoding to ANSI in PowerShell 2.0

后端 未结 2 574
春和景丽
春和景丽 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:35

    PowerShell v2 doesn't recognize an argument Default for the parameter -Encoding. Use the argument Ascii to save a file with ANSI encoding:

    Set-Content -LiteralPath "$filePath" -Encoding Ascii
    

    or omit the parameter entirely (Set-Content defaults to ANSI encoding):

    Set-Content -LiteralPath "$filePath"
    

提交回复
热议问题