Powershell: Change language/culture settings for the current session/window.

Hi,

different language settings on your clients causes some administration issues when you are working with times (formats) or group names for example.

The best workaround is to switch to a unique language at the beginning of the script. This must be done at the thread. The following function switches the langauge. Requierment is, of course 🙂 , the language pack is installed.

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

    process {
        $oCulture = [System.Globalization.CultureInfo]::CreateSpecificCulture($LanguageName)

        $oAssembly = [System.Reflection.Assembly]::Load("System.Management.Automation")
        $oType = $oAssembly.GetType("Microsoft.PowerShell.NativeCultureResolver")
        $oField = $oType.GetField("m_uiCulture", [Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Static)
        $oField.SetValue($null, $oCulture)
    }
}

For example: Switch to German:

Set-PowerShellUICulture -LanguageName de-DE

Michael

One thought on “Powershell: Change language/culture settings for the current session/window.”

  1. This does not work on PowerShell 7:

    InvalidOperation:
    Line |
    11 | $oField.SetValue($null, $oCulture)
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | You cannot call a method on a null-valued expression.

    Any idea how to fix? Thanks

Leave a Reply