Reputation: 357
I am running two Powershell scripts. One Powershell script adds the host name to a text file. Other Powershell script appends the ip address of the machine to the same file. So, the .txt file looks as follows: hostname ipaddress But, this file is being saved in Unicode format by default. What can I do so that, the text file is stored in ANSI format?
I use PowerShell v2.0.
[System.Text.Encoding]::Default
IsSingleByte : True
BodyName : iso-8859-1
EncodingName : Western European (Windows)
HeaderName : Windows-1252
WebName : Windows-1252
WindowsCodePage : 1252
IsBrowserDisplay : True
IsBrowserSave : True
IsMailNewsDisplay : True
IsMailNewsSave : True
EncoderFallback : System.Text.InternalEncoderBestFitFallback
DecoderFallback : System.Text.InternalDecoderBestFitFallback
IsReadOnly : True
CodePage : 1252
Upvotes: 1
Views: 31663
Reputation: 357
The following solved my problem:
Out-File 'file.txt' -Append -Encoding Ascii
This enabled me to save the file in ANSI format.
Upvotes: 3
Reputation: 1465
Depending on how you are outputting your text you may need to set the encoding type. Using Out-File -Encoding
you use the type of ASCII
. This also depends on the version of Powershell you're using.
See: SS64 Out-File and Set the encoding to ANSI in PowerShell 2.0
Upvotes: 7