I work in an enterprise environment with hundreds upon hundreds of Windows servers (all in a single AD domain), both locally and in other countries. I'm often required to log into an RDP session on various servers and, sometimes, I may forget to log off before closing the window. Obviously, this is not ideal, and I'd like to know if anybody knows a way to scan a domain for remote sessions running from my (or another user's, for that matter) account. Thanks!
4 Answers
Why not just set GPOs for the server for session idle timeouts so if you forget about one it automatically logs you off after a certain amount of inactive time. Set it for a couple of hours or more. Worst case you forget when you leave for the day and the servers automatically disconnect you that night.
If you want to do this yourself and actually go look for these suckers you could easily script it out, here's the MSFT CLI docs for TS
![](../../users/profiles/42617.webp)
- 6,059
- 2
- 23
- 36
-
Sometimes it is necessary to leave sessions open for days... large data transfers, etc. Otherwise, that would be a great solution. – Rob C. Sep 18 '12 at 20:52
-
Why aren't you using UNC file paths for data transfers instead of through the RDP shell. That would take longer than the built in network file copy process. – Brent Pabst Sep 18 '12 at 21:50
-
All this being said, we use a product at work called Remote Desktop Manager from Devolutions that allows you to view connections and sessions, assuming users have connected through the software tool. It does have some other benefits too though. – Brent Pabst Sep 18 '12 at 21:51
-
When migrating data from non-domain member servers following acquisitions, I generally map a network drive (which requires domain creds) and kick off a Robocopy. Since the servers are usually not physically accessible to me and ILO or DRAC haven't been configured, I can't do it from the console, so I need to leave the session running for the duration of the migration. Fun, huh? – Rob C. Sep 19 '12 at 17:42
This should do it:
for /f %i in (servers.txt) do query user jsmith /server:%i
You can eliminate jsmith if you want to display all usernames.
If used in a cmd script, double the percent sign:
SETLOCAL
SET FilePath=%1%
SET UserNameToSearch=%2%
FOR /F %%i IN (%FilePath%) DO query user %UserNameToSearch% /server:%%i
ENDLOCAL
![](../../users/profiles/20701.webp)
- 34,339
- 3
- 52
- 81
-
This method worked rather well, once I pulled a list of servers! Thanks, Greg! – Rob C. Oct 04 '12 at 16:14
Have you tried the MMC Remote Desktop Management snapin? Microsoft also offers Remote Desktop Connection Manager
Should be easy to check what connections are open and if inactive
![](../../users/profiles/17607.webp)
- 4,494
- 21
- 30
- 30
-
Hi, thanks for the response. Unless I'm using these incorrectly, they don't seem to be able to do what I need which is, essentially, scan all the servers in my domain, and report back to me which ones have an open session with my username on it. – Rob C. Sep 18 '12 at 18:12
-
Hmmm I have the MMC snapin configured so that all my servers show in the snapin. It is then a simple matter to see what servers have open sessions. – Dave M Sep 18 '12 at 18:35
-
IF you have only RDP into the servers through Microsoft's Remote Desktop Connection Manager and saved all the servers that you have logged into... then there is an option to find the all your Disconnected sessions through List Sessions option. Select each server and right click on it and select list sessions tab option. It will open up a new window and show the list of all users sessions that are connected to the server(Active, Disconnected etc). Find your session and logoff from the server.