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
The following solved my problem:
Out-File 'file.txt' -Append -Encoding Ascii
This enabled me to save the file in ANSI format.