Skip to content

Instantly share code, notes, and snippets.

@Xainey
Created January 25, 2018 15:16
Show Gist options
  • Save Xainey/e9b51d3c528d494a59ac5719ec6e3f21 to your computer and use it in GitHub Desktop.
Save Xainey/e9b51d3c528d494a59ac5719ec6e3f21 to your computer and use it in GitHub Desktop.
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