How To Disconnect Terminal Server Sessions Using Command Line?

by Nirmal Sharma [Published on 28 July 2009 / Last Updated on 4 April 2009]

This article explains a command you can use to disconnect the Terminal Server Sessions for a particular server remotely or on the servers mentioned in a text file.

Sometimes users forget to logoff their sessions from the Terminal Server computers. When you try to log on to those servers you get "There are no sessions left". In this situation, you need to disconnect user's session from the Terminal Server using either the Terminal Server Manager or command line tool. This article explains how you can use a command line tool from a remote computer to do so:

1. Steps for disconnecting a Sesion from a Single Server:

  • Query all the sessions on the Terminal Server by running the following command:

Query Sessions /server:Server_Name

  • Note down the ID of the session you want to disconnect.
  • Run the following command to disconnect user's session from the Terminal Server

Logoff ID_Number /Server:Server_Name

2. Steps for disconnecting a Sesion from a Single Server:

Create a text file: Servers.txt

Copy all the server names in the text file.

Next run the following command to see the Session ID on one server:

Query Sessions /server:Server_Name

  • Note down the ID of the session you want to disconnect.
  • Run the following command to disconnect user's session from all the Terminal Servers

For /F "Tokens=*" %a in (Servers.txt) Do Logoff ID_Number /Server:%a 

The above command will disconnect the same session from all the servers mentioned in the Servers.txt file.

 

Featured Links