I would like to query all users currently logged in to my computer with powershell. My current solution looks like this:
$userObject = quser /server:localhost 2>&1 | ForEach-Object -Process { ($_ -replace '\s{2,}', ';').Trim() } | ConvertFrom-Csv -Delimiter ';'
This gives me the currently logged in users, but the language for the header column depends on the system language. So if I run the script on a system with english as system language I get the following result
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
random console 1 Active none 4/7/2021 6:52 AM
If I run the exactly same command on a german system I get the following:
BENUTZERNAME SITZUNGSNAME ID STATUS LEERLAUF ANMELDEZEIT
random console 1 Aktiv 1+02:29 07.04.2021 19:10
The same on a french system, you get it...
I also tried to replace the default headers with my custom ones by using this code
$header = 'UserName', 'SessionName', 'ID', 'State', 'IdleTime', 'LogonTime'
$userObject = quser /server:localhost 2>&1 | Select-Object -Skip 1 | ForEach-Object -Process { ($_ -replace '\s{2,}', ';').Trim() } | ConvertFrom-Csv -Header $header -Delimiter ';'
but this only changes the headers but not the language dependent "state" property, so if I would like to filter the users by the state I would still have to convert the property to the correct language.
Any help is much appreciated