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.
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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:
1 | Set-PowerShellUICulture -LanguageName de-DE |
Michael
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