How to get connected remote desktop users on computers using PowerShell?


To get the user sessions on the remote computers using PowerShell, we need to use the cmd query command. First of all, we will get the user sessions on the local computer using the below command.

Example

query session

Output

Let’s see what are other supported parameters for the query session command.

Example

PS C:\> query session /?
Display information about Remote Desktop Services sessions.

QUERY SESSION [sessionname | username | sessionid]
              [/SERVER:servername] [/MODE] [/FLOW] [/CONNECT] [/COUNTER] [/VM]

sessionname         Identifies the session named sessionname.
username            Identifies the session with user username.
sessionid           Identifies the session with ID sessionid.
/SERVER:servername  The server to be queried (default is current).
/MODE               Display current line settings.
/FLOW               Display current flow control settings.
/CONNECT            Display current connect settings.
/COUNTER            Display current Remote Desktop Services counters information.
/VM                 Display information about sessions within virtual machines.

To get the sessions on the remote computers, we can use /Server:ServerName switch.

Example

query session /server:Test1-win2k12

Output

Updated on: 15-Dec-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements