How To Disconnect Terminal Server Sessions Using Command Line?

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.

 

About Nirmal Sharma

Nirmal is a Microsoft MVP in Directory Services and working as a Technical Architect/Consultant. He has been involved in Microsoft Technologies since 1994 and followed the progression of Microsoft Operating Systems and software. He is specialized in Directory Services, Microsoft Clustering, SQL, MOM, Exchange and Citrix. In his spare time, he likes to help others and write "internal" technical articles, white papers and tips on various Microsoft technologies. You can contact him at nirmal_sharma@mvps.org.


Article not looking right or info is missing? Let us know so that we can fix it: .


Receive all the latest articles by email!

Receive Real-Time & Monthly WindowsNetworking.com article updates in your mailbox. Enter your email below!
Click for Real-Time sample & Monthly sample

Become a WindowsNetworking.com member!

Discuss your network issues with thousands of other network administrators. Click here to join!

Community Area

Log in | Register

Readers' Choice

Which is your preferred Anti Spam Hardware solution?

Follow TechGenix on Twitter