Skip to content

Microsoft Powershells output is not local system language independet or - why "query user" sometimes returns USERNAME and BENUTZERNAME

I am working in an enviroment where some systems have a locale (or how microsoft is calling it "culture") of "en-US" or "de-DE".

Today I had to debug a script that is not outputting something. After a while, I've figured out that the result of query user /server:<server> is returning objects with different properties.

If the current locale is en-US, the property USERNAME exists. If the current locale is de-DE, the property BENUTZERNAME exists.

This is pretty sad since I could not find a way to set the culture within my powershell script to en-US.

What I've tried and what did not worked.

[System.Threading.Thread]::CurrentThread.CurrentCulture = "de-DE";
[System.Threading.Thread]::CurrentThread.CurrentUICulture = "de-DE";
[cultureinfo]::currentculture = 'de-DE';
[cultureinfo]::CurrentUICulture = 'de-DE';
Set-Culture de-DE

How did I solved it? I've added an or condition to support both properties, which is sad.

Where-Object { ($_.USERNAME -like "*$userNameToFilterAgainstOrNull*") -or ($_.BENUTZERNAME -like "*$userNameToFilterAgainstOrNull*") }

Good luck!

Translate to de es fr it pt ja