PowerShell – Disconnect a user from a Remote Desktop connection

In most cases, users do not disconnect properly from their Remote Desktop Connection (RDP).

This can cause performance problems for the server since the processes remain open. Anomalies may also be encountered on the display when reconnecting your user.

Although there are methods to allow forced disconnection of users, we will see how to disconnect a user connected to TSE / RDS using PowerShell.

Procedure

First, list all the users connected to your remote desktop server.

Use the command :

query session /server:<ServerName>

 

Identify the ID of the person whose session you want to disconnect.

Here we want to kill the user ending with “bars“, so the ID is 5.

Now, to apply this method, using the reset session command :

reset session <ID> /server:<ServerName>

 

The user is properly logged out and all processes have been killed.

 

Please follow and like us:
Microsoft engineer and Virtualization, I am at first computer-savvy. I share my time between this website, my engineering job and an intense sporting activity.