We have 3 terminal servers and end up having to kick off a user daily. I am totally new to PS and learning what I can, but having problems here with this.
The script prompts for the username, then searches the 3 servers to find which one they're on and gives me their Session ID. I then have to input the server # and Session ID and run the Invoke-RDUserLogoff command, but the problem is, I need to run that command as my domain admin account... my standard user account does not have permissions to do this.
Maybe there's even a completely different/better way to do this?
Thanks in advance.
$user = read-host -prompt "What is the USERNAME you need to disconnect?"
$term1 = qwinsta /server:ts1 | findstr "$user"
$term2 = qwinsta /server:ts2 | findstr "$user"
$term3 = qwinsta /server:ts3 | findstr "$user"
write-host TS1
$term1
write-host TS2
$term2
write-host TS3
$term3
$term = read-host -prompt "Which terminal server is the user on? (1, 2, or 3?)"
$id = read-host -prompt "To logoff the user, enter their ID #:"
Invoke-RDUserLogoff -HostServer ts$term -UnifiedSessionID $id -Force