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

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.