Script to terminate disconnected windows terminal sessions.

Posted on 2012-09-21
Last Modified: 2012-09-23
We are facing RDP issues when ever connecting to few win 2k3 servers .

Getting too many users logged into server.

Normally we use tsadmin and logoff all the disconnected sessions or use Windows Command line:

query user logoff session id

Is there any script where we can give inputs of few servers , which can monitor regularly and kill/logoff all the disconnected sessions .

The script can reduce our manual job. Even kindly let me know if we have any group policy to terminate disconnected sessions at a regular time interval.
Question by:AhmedAliShaik
    LVL 2

    Author Comment

    Even we have the below command to get the current terminal sessions and kill the disconnected sessions.

    Can we write some script using the commands identify disconnected sessions and kill them.
    Please suggest.

    Qwinsta sessionid /server:servername
    rwinsta sessionid /server:servername
    LVL 17

    Accepted Solution

    This is super easy, just configure session limits and users who go past them even if they are disconnected or inactive will be logged off.

    This shows you how:
    LVL 4

    Assisted Solution

    LVL 4

    Assisted Solution

    LVL 2

    Author Closing Comment

    Thanks All.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now