Reset Terminal Services Session Remotely

I had to log onto a Windows server today to run a script and was hit with the common "The terminal server has exceeded the maximum number of allowed connections." error.  No big deal, I'll just connect to the console session with "mstsc /console", right?  Apparently not.  It seems that the /console switch is gone and connecting to Session 0 remotely is no longer allowed.  There is now a /admin switch but that seems to only allow you to reconnect to an existing session that you initiated and in my case I needed to kick a different user off the box in order to connect. The solution was a few simple terminal services command line tools.  The QUERY command lets you view the active sessions on the server and RESET SESSION will let you boot off the offending user.

C:\>query session /server:SERVER01
No session exists for *

If you get this message it's likely because your account doesn't have the necessary rights on "server01". You can use "net use" to open a session on the remote server with different credentials.

C:\>net use /user:dom\adminaccount \\SERVER01\c$
Enter the password for 'dom\adminaccount' to connect to 'SERVER01':

Update: I've had issues using "net use" to open a session with different credentials.  A more reliable solution is to start a new command shell as an administrative account as shown below.

C:\>runas /user:dom\adminaccount cmd
Enter the password for dom\adminaccount:
Attempting to start cmd as user "dom\adminaccount" ...

After you enter your password you should be told the command completed successfully. Then you can issue the query command again.

C:\>query session /server:SERVER01
SESSIONNAME	USERNAME	ID	STATE	TYPE	DEVICE
console				0	Conn	wdcon
rdp-tcp				65536	Listen	rdpwd
rdp-tcp#113	user01		2	Active	rdpwd
		server01	4	Disc	rdpwd
		adminaccount	6	Disc	rdpwd

In this case I'm going to kill the connection for "user01" which is session 2.

C:\>reset session 2 /server:SERVER01

And now I'm good to go and can remote into my server to run my script.