Categories: Windows

Windows – Killing remotely hanging RDP session

You can't log in to RDP session on Windows 2003/Windows 2003 R2 server because you get a message that all sessions are taken, or you simply want to cleanup your RDP sessions from Windows 2008-2012R2 servers.

Solution

(Optional) Gain enough privilege to kill RDP connection on the server. This step is optional if you're already logged in with credentials that are valid for multiple sessions (such as domain environment)

net use servername_or_IP /USER:username “password“

List the connection to a particular server and get session ID.

query session /server:servername

Reset the session which you don’t need using ID of the session

reset session ID /server:servername_or_IP
Example
query session /server:TEST2003
SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
console                                     0  Conn    wdcon
rdp-tcp                                 65536  Listen  rdpwd
rdp-tcp#32        server-userid1            1  Active  rdpwd
rdp-tcp#33        server-userid2            2  Active  rdpwd

This post was last modified on August 15, 2018 23:36

Przemyslaw Klys

System Architect with over 14 years of experience in the IT field. Skilled, among others, in Active Directory, Microsoft Exchange and Office 365. Profoundly interested in PowerShell. Software geek.

Share
Published by
Przemyslaw Klys

Recent Posts

Active Directory Replication Summary to your Email or Microsoft Teams

Active Directory replication is a critical process that ensures the consistent and up-to-date state of…

4 weeks ago

Syncing Global Address List (GAL) to personal contacts and between Office 365 tenants with PowerShell

Hey there! Today, I wanted to introduce you to one of the small but excellent…

5 months ago

Active Directory Health Check using Microsoft Entra Connect Health Service

Active Directory (AD) is crucial in managing identities and resources within an organization. Ensuring its…

7 months ago

Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module

In today's digital age, the ability to create compelling and informative HTML reports and documents…

8 months ago

How to Efficiently Remove Comments from Your PowerShell Script

As part of my daily development, I create lots of code that I subsequently comment…

9 months ago

Unlocking PowerShell Magic: Different Approach to Creating ‘Empty’ PSCustomObjects

Today I saw an article from Christian Ritter, "PowerShell: Creating an "empty" PSCustomObject" on X…

9 months ago