0

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.

goodrone
  • 103
  • 4

3 Answers3

2

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      :
Ameer Deen
  • 3,598
  • 4
  • 26
  • 27
  • **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
0

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.

pk.
  • 6,451
  • 2
  • 42
  • 63
0

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