Jarrod
Jarrod

Reputation: 101

How can I find all RDP sessions disconnected for more than a day

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
}

Upvotes: 0

Views: 1395

Answers (1)

4c74356b41
4c74356b41

Reputation: 72151

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

Upvotes: 1

Related Questions