在本地化系统上强制以英文输出 PowerShell 错误 [英] Forcing PowerShell errors output in English on localized systems

查看:44
本文介绍了在本地化系统上强制以英文输出 PowerShell 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在各种操作系统上运行一些 PowerShell 脚本.他们中的大多数是英文版本,但是,有些是本地化的,例如德语、法语、西班牙语等.问题是本地系统管理员现在大多不使用 PowerShell,如果脚本失败并向他们抛出错误,而不是阅读它,他们只是将此类错误消息的屏幕截图发送给我,如果此错误的原因不明显,我会坚持将其输入到 g.翻译以了解发生了什么.

I need to run some PowerShell scripts across various operating systems. Most of them are in English version, however, some are localized for example German, French, Spanish, etc. The problem is local system administrators mostly do not now PowerShell and in the case the script fails and throws an error at them, instead of reading it they just send screenshots of such error messages to me and if the cause to this error is not obvious I am stuck with typing it to g. translate to find out what is going on.

是否有一个开关可以运行整个脚本或单个命令或一个参数或任何其他方式来强制 PowerShell 中的错误以英语而不是该特定机器的默认语言显示?

Is there a switch I can run the whole script or single command with or a parameter or any other way to force errors in PowerShell to be displayed in English instead of the language that is default for that particular machine?

推荐答案

您可以像这样更改管道线程的 CurrrentUICulture:

You can change the pipeline thread's CurrrentUICulture like so:

[Threading.Thread]::CurrentThread.CurrentUICulture = 'fr-FR'; Get-Help Get-Process

我使用的是英文系统,但在执行上述行之前,我更新了如下帮助:

I'm on an English system but before I executed the line above, I updated help like so:

Update-Help -UICulture fr-FR

这样,上面的 Get-Help 电话就为我的英语系统提供了法语帮助.注意:如果我把对 Get-Help 的调用放在一个新行上,它不起作用.确认 PowerShell 在每个管道开始之前重置 CurrentUICulture,这就是当命令在同一管道中时它起作用的原因.

With that, the Get-Help call above gave me French help on my English system. Note: if I put the call to Get-Help on a new line, it doesn't work. Confirmed that PowerShell resets the CurrentUICulture before the start of each pipeline which is why it works when the commands are in the same pipeline.

在您的情况下,您需要让人们使用以下方法安装英语帮助:

In your case, you would need to have folks install English help using:

Update-Help -UICulture en-US

然后像这样执行你的脚本:

And then execute your script like so:

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

这篇关于在本地化系统上强制以英文输出 PowerShell 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆