How do I script the logoff of disconnected RDP sessions?

There’s a (relatively) well known Group Policy that is designed to logoff idle/disconnected RDP sessions from terminal servers.  In reality, I’ve found it very hit and miss, and have now resorted to running a custom Scheduled Task to accomplish the same goal.

This script is designed to logoff any Disconnected session (on the machine where the script is run from) that has been idle for more than 1 hour.  I’ve deliberately left the option open to easily modify this to any preferred idle timeout, as you’ll see below with the if/elseif sections. This could be tidied up into a single ‘if’ block when you know what setting you’re using.

Note – you could also run this remotely (Windows Firewall state permitting) by changing the reference to “localhost” to any remote server.



2 Comments How do I script the logoff of disconnected RDP sessions?

  1. joe

    Hi Kamal, Is this a powershell script or a vbs script? Also, if I by remote server do you mean the actual server name? Is there a way to run this remotely to multiple servers, instead of having to specify each individual server?



Leave a Reply

Your email address will not be published. Required fields are marked *