There is a bunch of Windows Server 2008 R2 computers in the domain. They are used as workstations both for local and remote access. What is the right way to collect the information about logged on users? Including:

  • Who are logged on locally (Session=Console in terms of Remote Desktop Services Manager)
  • Who are logged on locally, but desktop is locked (State!=Active in terms of RDSM)
  • Who are logged on remotely
  • Who are logged on remotely, but desktop is locked
  • Logged on time (if possible)

I'd like to compile an HTML page with the information, so it'll be great to work out a script to do the job.

Solutions that didn't work for me:

For example, the PsLoggedOn utility (SysInternals) doesn't give information about the state (Active/Disconnected).

The Remote Desktop Services Manager is a great GUI tool, especially when added all the machines to the group. I need the same information via console interface.


You could just parse data from qwinsta. Qwinsta output normally looks something like this:

PS C:\> qwinsta
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 services                                    0  Disc
 console                                     1  Conn
>rdp-tcp#0         administrator             2  Active  rdpwd
 rdp-tcp                                 65536  Listen

The following queries for RDP connections by "SESSIONNAME":

$sessionInfo = qwinsta | foreach { (($_.trim() -replace "\s+",","))} | ConvertFrom-Csv
$rdpSessions = $sessionInfo | where {$_.SESSIONNAME -like ">rdp-tcp*"}

You'd get output similar to the below:

PS C:\> $rdpSessions

SESSIONNAME : >rdp-tcp#0
USERNAME    : administrator
ID          : 2
STATE       : Active
TYPE        : rdpwd
DEVICE      :
  • Excellent, it's almost 90% done by now! But now both active and locked desktops give the save "Active" state. I think there should be some way to query a session and find out its desktop state. – goodrone Sep 15 '11 at 11:43

I haven't worked with it (since I don't have any R2 Terminal Servers) so I could be wrong, but the RDS Provider in Powershell should give you everything you need. Take a look at this if you're interested.


PDQ Inventory is a (free) tool that gives you an insight of all online computers in your network. It's also possible to export to Excel.

Name    Online  Scan Status O/S O/S Version O/S Service Pack    Uptime  Current User    Successful Scan Date
PC005   Yes     8.1 6.3.9600    0   22 minutes  BUGGEGRP\USER01 (locked)    26/04/2016 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.