在 PowerShell V2 中,以下返回当前编辑器的编码
$a=$psise.CurrentPowerShellTab.Files[0]
$a.gettype().getfield("encoding","nonpublic,instance").getvalue($a)
与
$a=$psise.CurrentPowerShellTab.Files[0]
$a.gettype().getfield("encoding","nonpublic,instance").setvalue($a,[text.encoding]::ascii)
您可以将编码设置为 ASCII。参看。这个帖子
尝试使用 PowerShell V3 失败。显然 getfield() 不返回任何对象。有什么想法可以解决这个问题吗?