Hello, Dear Colleagues.
I have a PS script to query user's session ID from remote workstations.
$machinelist = "pc01", "pc02", "pc03" foreach ($machine in $machinelist){ $results = psexec \\$machine query user $id = $results | ? { $_ -match '(\d+)\s+Active' } | % { $matches[1] } $results $id }
Work fine in Powershell ISE x64, and does not in Powershell ISE x86.
First question: What the catch?
Error:
The term 'psexec' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:3 char:16 + $results = psexec \\$machine query user + ~~~~~~ + CategoryInfo : ObjectNotFound: (psexec:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Second question: there is a better way to query user's sessions ID from remote workstations?
Fount this, but works only in Powershell ISE x86. And too complicated for me now to modify this script for my need.
Thanks. Have a nice day.
PS.
Can be done without PsExec, but only on x64 ISE too:
$machinelist = "pc01", "pc02", "pc03" foreach ($machine in $machinelist){ $results = query user /server:$machine $id = $results | ? { $_ -match '(\d+)\s+Active' } | % { $matches[1] } $results $id }
The same error:
The term 'query' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:3 char:16 + $results = query user /server:$machine + ~~~~~ + CategoryInfo : ObjectNotFound: (query:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundExceptionAnd both questions are still of current interest.
- Edited by fapw Thursday, January 29, 2015 2:18 PM