Powershell 将文本文件转换为ANSI格式
我正在运行两个Powershell脚本。一个Powershell脚本将主机名添加到文本文件中。其他Powershell脚本将计算机的ip地址附加到同一文件。 因此,.txt文件如下所示: 主机名 IP地址 但是,默认情况下,此文件以Unicode格式保存。我该怎么做才能使文本文件以ANSI格式存储 我用 PowerShell v2.0Powershell 将文本文件转换为ANSI格式,powershell,text,unicode,encoding,ansi,Powershell,Text,Unicode,Encoding,Ansi,我正在运行两个Powershell脚本。一个Powershell脚本将主机名添加到文本文件中。其他Powershell脚本将计算机的ip地址附加到同一文件。 因此,.txt文件如下所示: 主机名 IP地址 但是,默认情况下,此文件以Unicode格式保存。我该怎么做才能使文本文件以ANSI格式存储 我用 PowerShell v2.0 [System.Text.Encoding]::Default IsSingleByte : True BodyName : iso-8859-1 Enco
[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
根据您输出文本的方式,您可能需要设置编码类型。使用
Out File-Encoding
可以使用ASCII
类型。这还取决于您使用的Powershell版本
请参阅:和以下内容解决了我的问题: 输出文件'File.txt'-Append-Encoding Ascii
这使我能够以ANSI格式保存文件 您使用的PowerShell版本是什么?
[System.Text.Encoding]::Default
返回什么?如何写入该文件?