Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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*"}
$rdpSessions

You'd get output similar to the below:

PS C:\> $rdpSessions


SESSIONNAME : >rdp-tcp#0
USERNAME    : administrator
ID          : 2
STATE       : Active
TYPE        : rdpwd
DEVICE      :
share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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