How to get Remote Desktop Sessions (RDP) using Powershell

In Powershell, we can get a list of remote desktop sessions (rdp) using the commands QWinsta and Query.

List Remote Desktop Sessions using QWinsta:

QWinsta /server:[Server name or IP]

Replace the parameter [Server name or IP] with the name or IP address of the remote machine.

QWinsta /server:210.168.1.54

Get Remote Desktop Sessions using Query:

Query user /server:[Server name or IP]

Replace the parameter [Server name or IP] with the name or IP address of the remote computer.

Query user /server:210.168.1.54

You can use the below powershell command to get clear output.

(Query user /server:210.168.1.54) -replace 's{2,}', ',' | ConvertFrom-Csv

The following command exports the output to CSV file.

(Query user /server:210.168.1.54) -replace 's{2,}', ',' | ConvertFrom-Csv |
Export-CSV "C:\RDPSessions.csv" -NoTypeInformation -Encoding UTF8
Advertisement

1 thought on “How to get Remote Desktop Sessions (RDP) using Powershell”

Leave a Comment