Server 2012 RDP: Logoff all disconnected sessions
-
In looking at my RDP server, I have a number of disconnected sessions. I know that I can log them off one at a time via Server Manager or Task Manger.
But is there a Powershell or CMD which would do the same - for ALL disconnected session at one time.
I'm googling - not coming up with anything right at the moment.
-
Edit: Not sure if it will work with 2012.
https://docs.microsoft.com/en-us/powershell/module/remotedesktop/invoke-rduserlogoff?view=win10-ps -
@black3dynamite said in Server 2012 RDP: Logoff all disconnected sessions:
Edit: Not sure if it will work with 2012.
https://docs.microsoft.com/en-us/powershell/module/remotedesktop/invoke-rduserlogoff?view=win10-psI read that and didn't understand it (at first) an hour later I think I do.... I really again don't want to do one at a time (ID)..
-
@gjacobse said in Server 2012 RDP: Logoff all disconnected sessions:
@black3dynamite said in Server 2012 RDP: Logoff all disconnected sessions:
Edit: Not sure if it will work with 2012.
https://docs.microsoft.com/en-us/powershell/module/remotedesktop/invoke-rduserlogoff?view=win10-psI read that and didn't understand it (at first) an hour later I think I do.... I really again don't want to do one at a time (ID)..
You can also set up a time limit for auto logoff using group policy.
https://4sysops.com/archives/automatically-log-off-idle-users-in-windows/ -
-
I have a Powershell script that I use to do this.
The code written as is is part of a larger program PS script I wrote to manage some things.
As it is written, it will forcibly log off anybody who is "DISCONNECTED" in the RD Server. I'd recommend running this from the Connection Broker. (Set the $connectionbroker line in the script regardless).
https://raw.githubusercontent.com/dafyre/PoweshellScripts/master/RDS-Force-Disconnected-Logoff.ps1
-
Thanks for sharing the script, dafyre. Will give it a try, too.