How to remove connected remote desktop user sessions using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

We can remove connected RDP sessions using PowerShell and for that, we can use the cmd command “reset session” in PowerShell.  Let’s see the supported parameters for it.

Example

PS C:\> reset session /?
Reset the session subsytem hardware and software to known initial values.

RESET SESSION {sessionname | sessionid} [/SERVER:servername] [/V]

sessionname         Identifies the session with name sessionname.
sessionid           Identifies the session with ID sessionid.
/SERVER:servername  The server containing the session (default is current).
/V                  Display additional information.

We can provide here session ID or Name and also the remote server name.

Suppose we have below active sessions on a remote computer called Test1-Win2k12,

We can disconnect the remote sessions using Session Name or the Session ID. First, we will disconnect the remote sessions with session ID 1.

reset session 1 /server:test1-win2k12

When we query the session again,

Example

query session /server:Test1-win2k12

Output

Now we will disconnect the session called rdp-tcp#0 using the SessionName,

reset session rdp-tcp#0 /server:test1-win2k12

Let’s query the session again and it should get disconnected from the remote server.

raja
Published on 15-Dec-2020 12:30:01
Advertisements