6

I often find myself RDP into multiple machines and have the connection time out, keeping me logged in. I then forget where I've been and my account stays logged in, blocking other users from accessing those machines.

Is there any way to query a user on a domain and list all the machines that user is logged into?

Volodymyr Molodets
  • 2,404
  • 9
  • 35
  • 52
Sio
  • 165
  • 1
  • 1
  • 3
  • 1
    Not exactly, but qwinsta.exe can help - http://serverfault.com/search?q=qwinsta – August Feb 11 '13 at 12:55
  • 1
    Sometimes I connect to the remote hosts through **cmd**, i.e. you simply type in **"mstsc /v hostnameORip-address"** and hit Enter. Even in case if your connection times out, you still have the history of hosts you've connected to in CMD window. – Volodymyr Molodets Feb 11 '13 at 13:00

3 Answers3

5

You can use PowerShell to find where your user is logged into. You will need the Active Directory cmdlets though:

# Import the Active Directory module for the Get-ADComputer CmdLet
Import-Module ActiveDirectory

# Query Active Directory for computers running a Server operating system
$Servers = Get-ADComputer -Filter {OperatingSystem -like "*server*"}

# Loop through the list to query each server for login sessions
ForEach ($Server in $Servers) {
    $ServerName = $Server.Name

    # When running interactively, uncomment the Write-Host line below to show which server is being queried
    # Write-Host "Querying $ServerName"

    # Run the qwinsta.exe and parse the output
    $queryResults = (qwinsta /server:$ServerName | foreach { (($_.trim() -replace "\s+",","))} | ConvertFrom-Csv) 

    # Pull the session information from each instance
    ForEach ($queryResult in $queryResults) {
        $RDPUser = $queryResult.USERNAME
        $sessionType = $queryResult.SESSIONNAME

        # We only want to display where a "person" is logged in. Otherwise unused sessions show up as USERNAME as a number
        If (($RDPUser -match "[a-z]") -and ($RDPUser -ne $NULL)) { 
            # When running interactively, uncomment the Write-Host line below to show the output to screen
            # Write-Host $ServerName logged in by $RDPUser on $sessionType
            $SessionList = $SessionList + "`n`n" + $ServerName + " logged in by " + $RDPUser + " on " + $sessionType
        }
    }
}


# When running interactively, uncomment the Write-Host line below to see the full list on screen
$SessionList

You will just need to tweak this for your situation. (i.e. computers and servers, not just servers)

colealtdelete
  • 6,009
  • 1
  • 29
  • 34
3

Is there any way to query a user on a domain and list all the machines that user is logged into?

No. That's not how it works; there's nothing like an ~IsLoggedOnTo attribute that attaches to the user object in AD. The list of users logged is a property/attribute of each computer individually, so you'd have to query each computer individually.

I'd [probably] use PowerShell and the TS Manager/Remote Desktop Services MMC snap-in to figure it out... if it weren't a lot easier to just either remember or get into the habit of logging out, rather than closing my RDP windows.

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
-1

So - get a list of all servers in your domain (and/or whatever machines might be in question.) Put it in a file called servers.txt. Run :

 for /f %s in (servers.txt) do (echo %s & qwinsta /server:%s )

-- txt file example --

 server1
 server2
 server3
masegaloeh
  • 17,978
  • 9
  • 56
  • 104
macunte
  • 101