1

I read English Output , where it gives this function to force PowerShell output in English

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)
    }
}

This only seems to work half-way, as line 2 here contains Norwegian "Ingen Tilgang", which means "Access Denied".

get-acl *                                                                                                     
get-acl : Ingen tilgang
At line:1 char:1
+ get-acl *
+ ~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Acl], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetAclCommand

Any other way I can force output to be en English?;)

Jason Hunter
  • 495
  • 1
  • 4
  • 11
  • 1
    This is not PowerShell's problem, unfortunately -- it's the .NET exception messages which insist on remaining localized. [See also](https://stackoverflow.com/a/209259/4137916) -- although you can sometimes get these correct as well by changing the UI culture, this doesn't work for all exceptions. – Jeroen Mostert Feb 01 '23 at 14:16
  • If I start the shell process with en_US, that'll work, then? – Jason Hunter Feb 01 '23 at 17:03
  • I don't see the symptom in Windows PowerShell v5.1.22621.963 (W11 22H2) - once your function is executed, even .NET exceptions respect the new setting (an easy way to provoke one is `1 / 0`). What version / OS are you using? – mklement0 Feb 01 '23 at 18:50
  • OsHardwareAbstractionLayer : 10.0.22621.819 and PSVersion : 5.1.22621.963 – Jason Hunter Feb 02 '23 at 07:16

0 Answers0