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:
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
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

$PSVersionTable.PSVersion

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

Open in new window

LVL 3
ivan rosaAsked:
Who is Participating?
 
oBdACommented:
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

0
 
ivan rosaAuthor Commented:
thanks oBdA,

I just found another way also, i made a research for that 'query' and happen to be in
C:\Windows\WinSxS\amd64_microsoft-windows-t..es-commandlinetools_31bf3856ad364e35_10.0.16299.15_none_079c85586a28af6b

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...,
0
 
ivan rosaAuthor Commented:
Thanks a lot bud!
0
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.