Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 418 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Forcing PowerShell errors output in English on localized systems

#1
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.

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?
Reply

#2
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

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
Reply

#3
`[Threading.Thread]::CurrentThread.CurrentUICulture` only affects to current one-liner, so you can use it for execution of single .ps1 file.

If you want to change messages to English throughout every command in a PowerShell window, you have to change the culture setting cached in PowerShell runtime with reflection like this:

```ps1
# example: Set-PowerShellUICulture -Name "en-US"

function Set-PowerShellUICulture {
param([Parameter(Mandatory=$true)]
[string]$Name)

process {
$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture($Name)

$assembly = [System.Reflection.Assembly]::Load("System.Management.Automation")
$type = $assembly.GetType("Microsoft.PowerShell.NativeCultureResolver")
$field = $type.GetField("m_uiCulture", [Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Static)
$field.SetValue($null, $culture)
}
}
```

(from )
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through