During a recent trip to Redmond, Microsoft said that Server Core will be the preferred deployment type in Windows Server 8. This means that server management is about to become a lot more command-line oriented, so it's a good idea to familiarize yourself with some useful commands.
One way to prepare is by looking at how common tasks are performed at the command line in Windows Server 2008. That way, when Windows Server 8 does ship, the idea of command-line management won't be quite so daunting. With that philosophy in mind, let's look at five commands for managing Remote Desktop Services.
The Query Session command is used to retrieve information about the sessions that are in effect on your Remote Desktop Server. As you can see in Figure A below, entering the Query Session command provides a quick summary of all of the sessions (whether the sessions are active or not).
Occasionally, you need to reset a specific session (which I will discuss in a moment). In these types of situations, it is helpful to know the session ID. If you have a lot of users connected to the server then reading through the list of sessions, hunting for one specific session may be impractical. Thankfully, there are some ways in which you can use commands to retrieve the information that you need. For example, suppose that you needed to know about a session belonging to a user named User1. You could find the information by using this command:
Query Session User1
Likewise, it is also possible to query a server. For instance, if you wanted to see all of the sessions for a server named TS1 you could use this command:
Query Session /Server:TS1
There are a number of other command line switches that can be used with the Query Session command. You can view the full command syntax by typing the following command:
Query Session /?
Earlier, I mentioned that it is sometimes necessary to reset a session and that in those cases, it is helpful to know the session ID. If you look back at the previous figure, you will notice that the administrator is logged in and has been assigned a session ID of 1. If you wanted to reset this session then you would use the following command:
Reset Session 1
It is also possible to reset a session by name. For instance, in Figure A, the administrator's session is called RDP-TCP#0. You could substitute the session name for the session ID. To reset this session you could use this command:
Reset Session RDP-TCP#0
Another useful command is Query User. The Query User command works like the Query Session command, except that it allows you to get information for specific users. As you can see in Figure B, entering the Query User command by itself shows all of the users who are logged into the server.
Most often, the Query User command is combined with a username, session name or session ID. For example, if you wanted to know about a session for a user named User1, you could enter this command:
Query User User1
If you ever need to take a Remote Desktop Server down for maintenance, you have to make sure that all of the users are logged off first. This is where the Change Logon command comes into play. You can use the Change Logon command to control whether users are allowed to log on to the Remote Desktop Server. For instance, in Figure C you can see how the Change Logon command was used with the Disable switch to disable user logons. User logons could be re-enabled by using the /Enable switch.
There are a couple of other handy switches to know as well. The Drain switch disables new user logons, but allows reconnections to existing sessions. Similarly, the DrainUntilRestart command works the same way as the Drain switch, but logons are only rejected until after the server has been restarted.
Earlier, I showed you how to reset a session. Every once in a while you might find that you actually have to go so far as to disconnect a user's session. This can be accomplished via the TSDiscon command. Simply combine this command with the session ID or the session name of the session that you want to disconnect. For example, if you wanted to disconnect session 1 then you would use this command:
Of course, there are many other commands that can be used to manage Remote Desktop Services, but the commands I have shown give you an idea of the types of management tasks that can be performed at the command line.
ABOUT THE AUTHOR:
Brien M. Posey, MCSE, is a Microsoft Most Valuable Professional for his work with Windows 2000 Server and IIS. He has served as CIO for a nationwide chain of hospitals and was once in charge of IT security for Fort Knox. As a freelance technical writer, he has written for Microsoft, TechTarget, CNET, ZDNet, MSD2D, Relevant Technologies and other technology companies.