I want a script to log off any disconnected remote desktop sessions (not idle, but when they close their session window without logging out). I have a script, shown below, which works on any particular server it is ran on. So I *could* put this script on each server and have it run through task scheduler.
I would prefer to have it run once, on the DC, and run the script once for each server listed in a text file. Furthermore, I would like to be able to have a text file of user names, so that if a disconnected session is from one of the users listed, that session will be exempt from being logged off.
I don't know how to read things from a file or run the script multiple times. The script I have, I found online and modified slightly to get where I'm at now.
Here's what I have:
$hostn = get-content env:computername $pc = qwinsta...