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:
Set-Content -LiteralPath "$filePath" -Encoding Default
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:
Set-Content -LiteralPath "$filePath" -Encoding Default
PowerShell v2 doesn't recognize an argument
Default
for the parameter-Encoding
. Use the argumentAscii
to save a file with ANSI encoding:or omit the parameter entirely (
Set-Content
defaults to ANSI encoding):I use the
.NET
WriteAllText
function for that:Ensure the default encoding reflects your desired output using:
Otherwise, add the enum with the desired encoding as the third parameter.