0

I'd like to write a PS script to find any user who has a disconnected RDP session on a server, if it's been disconnected for longer than one day. Ultimately either email myself the results. I'm trying to use the quser command as that seems to have the info I want, but I can't seem to do anything with those results. Here is what I have so far.

$Servers = Get-ADComputer -Filter * -SearchBase "OU=Servers,DC=domain,DC=com"

foreach ($Server in $Servers) {
    $Results = (quser /server:$ServerName)
    Write-Host $Results
}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Jarrod
  • 91
  • 2
  • 3
  • 10
  • What do you need this for? You could simply configure the Terminal Services to terminate disconnected sessions after a day. – Ansgar Wiechers May 23 '17 at 21:19
  • I have posted the answer to something similar here: https://stackoverflow.com/questions/43352905/powershell-to-find-out-disconnected-rdp-session-and-log-off-at-the-same-time/43352906#43352906 – LT- Aug 09 '18 at 12:49

1 Answers1

1

Just split the results by space and store into array:

$parsedresult = $result -split ' +'

then the second or the third column would be the state and all the rest I don't remember ;) probably something like 5th column would be time. you can figure it out by looking at the quser output

4c74356b41
  • 69,186
  • 6
  • 100
  • 141