QUERY - Command

Hi Folks,
the following line command query will work great if I do it in my Lab under powershell
query user /server:$Client | Select-String "active"

Open in new window

will output:
JohnnyC                      console             1  Active      none   3/5/2018 10:31 AM

however when in Production(different pilot PC) it will throw an error:
user : The term 'quser' 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.
but whats even more odd, is that the  command works in DOS...
has anybody gotten the same issue? or does anybody knows how to replicate that line into powershell cmdlets

this is my Powershell version


Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      16299  248

Open in new window

ivan rosaAsked:
Who is Participating?
Are you maybe running this on a 64bit system, but in a 32bit PS console? query.exe/quser.exe only exist in C:\Windows\system32, not in C:\Windows\syswow64.
So either use a 64bit PS console, or use the sysnative folder to execute the 64bit program from the 32bit PS (don't search for this folder - just use it as posted):
& 'C:\Windows\sysnative\query.exe' user /server:$Client | Select-String "active"

Open in new window

ivan rosaAuthor Commented:
thanks oBdA,

I just found another way also, i made a research for that 'query' and happen to be in

Open in new window

so from there I copied: query.exe & query.mui then copy it to my script folder.
then run it as:
.\query.exe user /server:localhost | Select-String "active"

Open in new window

I prefer your method better though, much cleaner as usual! are you relative of Jeff Snover by any chance? you sure know a LOT...,
ivan rosaAuthor Commented:
Thanks a lot bud!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.