如何让 PowerShell 以英文输出错误消息

如果你想以英文而不是本地语言查看 PowerShell 输出(例如错误消息),在你的命令前加上

example.ps1
[Threading.Thread]::CurrentThread.CurrentUICulture = 'en-US';

例如,为了以英文而不是本地语言运行 My-Cmdlet -Arg 1 的输出,使用

example.ps1
[Threading.Thread]::CurrentThread.CurrentUICulture = 'en-US'; My-Cmdlet -Arg 1

[Threading.Thread]::CurrentThread.CurrentUICulture 只影响当前命令,对其他命令没有任何影响。因此你需要在每个想以英文查看输出的命令前复制此命令。

可能你还需要安装英文帮助文件以查看更多英文消息。为此,在 PowerShell 中以管理员身份运行此命令:

example.ps1
Update-Help -UICulture en-US

Check out similar posts by category: PowerShell, Windows