Created
January 25, 2018 15:16
-
-
Save Xainey/e9b51d3c528d494a59ac5719ec6e3f21 to your computer and use it in GitHub Desktop.
Revisions
-
Xainey created this gist
Jan 25, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ 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 } } } }