Powershell to find logged in users...

You may find this useful.

I found that my account was getting locked out from some RDP session I'd disconnected sometime ago...naughty naughty...

Anyways here is some Powershell to list users with TS Sessions...

You need the PSTerminalServices add in http://archive.msdn.microsoft.com/PSTerminalServices

And to make things easier (for me) I created a list of all my servers called "serverlist.csv"

Import-Module PSTerminalServices

$MachineList = Get-Content -Path c:\serverlist.csv; # One system name per line
foreach ($Machine in $MachineList) {
    "---------" + $Machine + "---------"
    Get-TSSession -ComputerName $Machine -erroraction 'silentlycontinue' | Select UserName,State
    "---------------------------------"
}

Here's a version for specific username

Import-Module PSTerminalServices

$MachineList = Get-Content -Path c:\serverlist.csv; # One system name per line
foreach ($Machine in $MachineList) {
    "---------" + $Machine + "---------"
    Get-TSSession -ComputerName $Machine -erroraction 'silentlycontinue' | ?{$_.UserName -eq "my_username"} | Select UserName,State
    "---------------------------------"
}

Comments

Popular posts from this blog

PXE booting, MDT and 802.1x

Intune installation requires a wire...or does it?

Security Policy 1001