Disconnected-RDP
Find Disconnected/Orphaned Remote Desktop Sessions App
How I created a small App that helped our admins to stay on top of their disconnected and orphaned Remote Desktop Connections (RDP).
Reason for developing it:
- The primary goal: We automate our password changes so if the AD account password is changed while there is still an RDP connection left behind that is using the old password, the AD account would lock out.
- Users have more control and visibility over their RDP connections.
- Some RDP connections were left open willingly to run jobs or processes, so I didn’t want to force a logoff policy.
Development:
Front-end is developed in vb.net and backend is developed in PowerShell.
Back-end process (PowerShell):
- Powershell script that runs every 5 minutes and queries all enabled (only) AD servers (computer accounts). Command used: Query User /Server:ServerName
- Saves all sessions into a variable
- Formatting and sorting:
- Format sessions in CSV format
- Filter and select only disconnected sessions
- Filter further and select only admin account sessions
- Save all disconnected sessions info for each user in a separate CSV file (file/peruser.)
Front-end process (vb.net):
- Auto refresh every 10 seconds
- Get currently logged in username to look up the relevant CSV file
- Generate a .net grid view from the CSV file
- Force logoff button which creates a “UserName.Logoff” file, letting the second PowerShell script know that user wants to log off all their disconnected sessions.
Back-end script 2:
- Check for any “Username.Logoff” files
- If a logoff file is found then import disconnected RDP sessions from the CSV files (relevant to username) and start logging off the disconnected RDP sessions.
- Update the CSV file with success message.
Start here: https://github.com/ltiwana/Disconnected-RDP/wiki Read my LinkedIn post here: https://www.linkedin.com/pulse/how-i-created-small-app-helped-our-admins-stay-top-orphaned-tiwana/