Wednesday, October 24, 2018

Logging out Remote Desktop users from command line

You may on occasion find yourself needing to log a remote user from your Windows server.  To do so open PowerShell as administrator and run the following commands.


This will provide you with the username and ID of all currently logged in users.

query user

      USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
      user1                     rdp-tcp#6             17  Active               .  10/23/2018 8:19 PM

Once you have found the username you are looking for you can log them out by running the following command.

Invoke-RDUserLogoff -HostServer "servername" -UnifiedSessionID 17

You can run the "query user" command again to verify the user is no longer logged in.