Created
January 25, 2018 15:16
-
-
Save Xainey/e9b51d3c528d494a59ac5719ec6e3f21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-RDPUsers ($computers) { | |
process{ | |
foreach($computer in $computers) { | |
try { | |
$quser = quser /server:$computer 2>&1 | Select-Object -Skip 1 | |
foreach($user in $quser) { | |
$line = [regex]::split($user.Trim(), '\s{2,}') | |
$o = if ($line[2] -eq 'Disc') { 0 } else { 1 } | |
[PSCustomObject]@{ | |
ComputerName = $computer | |
UserName = $line[0] | |
SessionName = $null + $o | |
Id = $line[1 + $o] | |
State = $line[2 + $o] | |
IdleTime = $line[3 + $o] | |
LogonTime = $line[4 + $o] | |
} | |
} | |
} catch { | |
[PSCustomObject]@{ | |
ComputerName = $computer | |
Error = $_.Exception.Message | |
} | Select-Object -Property UserName,ComputerName,SessionName,Id,State,IdleTime,LogonTime,Error | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment