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

Upgrade Azure Active Directory Connect fails with unexpected error

Today, I made the decision to upgrade my test environment and update the version of…

2 months ago

Mastering Active Directory Hygiene: Automating Stale Computer Cleanup with CleanupMonster

Have you ever looked at your Active Directory and wondered, "Why do I still have…

3 months ago

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…

7 months 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…

12 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…

1 year 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…

1 year ago