Log off user session on remote machine using Powershell

This is a handy little tool you can use with Powershell or in command prompt to see who is logged onto a remote machine and to end there session. Great for servers when you get the "too many users already logged in" message when trying to access a server.

1. You need to get the session ID of a user to log off by running the following command:
 qwinsta /server:servername









2. Enter the following command with the session ID at the end to log the user of:
logoff /server:servername (session id)

I used these commands to put together the following script. It will prompt you for the server name and give you the output of current open sessions then prompt you for the session ID to log off. Enjoy:

$server = read-host "Hostname"

qwinsta /server:$server

$ID = read-host "Session ID to log off"

logoff /server:$server $ID

No comments:

Post a Comment