The QUser command gets logged-in users on the local as well as remote computer and displays their information like username, session name, state, and Logon Time.
Use the Quser
command on a Windows command prompt (cmd) or PowerShell terminal to find the user logged on to the remote computer.
While working on a remote server, you may receive a warning message from Windows that “Someone else is still using this PC. If you shut down now, they could lose unsaved work“. In this case, you may not be able to log in to the computer. QUser command helps to identify active user sessions on the remote computer.
The PowerShell QUser command displays information about users’ sessions on a remote server. Using the quser, you can get a list of users logged on to the server machine.
QUser Command
Syntax
quser [<username> | <sessionname> | <sessionID>] [/server:<servername>]
Run PowerShell or cmd with administrator access privileges to avoid the quser access denied error.
Cool Tip: Query Active Directory user’s info using PowerShell!
QUser Command Examples
QUser Command – Get logged on user on the remote computer
quser /server:it-cor20
In the above QUser command, it takes the quser /server parameter to get logged-on user information about remote computer it-cor-20.
It returns the list of all the users currently logged on to the remote desktop machine and prints output on the console as below with logged-on username, sessionname, sessionid, state, logon time.
PS D:\LogTest> quser /server:it-cor20
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
Tom console 1 Active None 27-07-2021 14:13
QU
ser command to get logged in user name on the remote computer
$users = quser /server:it-cor20 foreach($user in $users) { $parsed_User = $user -split '\s+' #Get UserName Write-Host $Parsed_user[0] }
In the above PowerShell QUser example, the Quser command gets the list of the logged-on user sessions to the remote computer.
Using the QUser /server command, it takes the remote hostname and gets the logged-on user sessions to the $users
variable.
We then iterate over the $users object using the foreach
to split the user object string to get a username and assign it to the $parsed_User
. Then, we use Write-Host
command to print and view logged-on users onto a remote computer.
QUser logoff or disconnect user
Using the PowerShell quser logoff command, you can log off any user with the session ID or session name that you get using the quser command
logoff 15 /server:it-cor20
In the above command, the quser log-off command disconnects session id 15 or logoff session quser from the it-cor20 server.
Cool Tip: Difference between Active Directory lastlogon and lastlogontimestamp!
Fix QUser Access Denied
Sometimes you may get QUser access denied issues as below while trying to get logged-on users’ information on the computer as given below.
C:\>quser
Error 0x00000005 enumerating sessionnames
Error [5]:Access is denied.
To fix the QUser access denied issue, open cmd in administrator mode, and for UAC remote restrictions, modify the registry on the remote computer.
Refer to UAC and Remote restriction
Important Note: Do a backup of the registry file before making any changes.
QUser Command Parameters
Parameters
quser command accepts the below parameters:
- <username> – the logon name of the user that you want to query
- <sessionname> – the name of the session you want to query
- <sessionid> – specifies the name of the session id you want to query
- /server:servername – specifies the name of the remote computer server that you want to query
- /? – display quser help
C:/>quser
The above Quser command in PowerShell consider default as the current machine for the server name to be queried and returns the list of the user logged on the current machine
QUser PowerShell command returns
- USERNAME – the name of the users currently logged on
- SESSIONNAME – the name of the session
- ID – session id
- STATE – Active or disconnected
- IDLE TIME – quser idle time for a user in a number of minutes since the last keystroke or mouse movement at the session
- logon time – date and time the user logon to the server
Conclusion
Hope you find out above article helpful and educational to get the list of logged-on users on the remote servers using the quser command in PowerShell.
The QUser logoff command will disconnect the session user using the session ID or session name.
You will need to have full access or special access to run the quser PowerShell command else it will give you a remote server access denied message. if you don’t specify the server name, it uses the current server as default to query and returns the users.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.