Windows 7 / Getting Started

Preparing for Server Maintenance

When you need to update an application, you certainly don't want users to be connected to it at the time. Therefore, you'll need some method of keeping users off the server when necessary. This is generally known as putting the server into drain mode, where existing connections are allowed to continue but no new ones are allowed in (and the RD Connection Broker won't route any connections there).

When preparing for maintenance, there are three steps you should perform, in order.

  1. Disable new logons.
  2. Inform users of the planned downtime.
  3. Shut down the RD Session Host server programmatically.

Disabling New Logons

You can put a server into drain mode via RD Session Host Configuration or the command line. From RD Session Host Configuration, move to the Edit Settings area in the middle pane and double-click User Logon Mode. This will open a dialog box presenting three options.

  • Allow All Connections: This is the default user mode. All connections are allowed.
  • Allow Reconnections, But Prevent New Logons: This is drain mode. Users with existing sessions are allowed to reconnect or to stay connected to the server, but new connections are blocked.
  • Allow Reconnections, But Prevent New Logons Until The Server Is Restarted: This is temporary drain mode. The server will not accept new connections (and the RD Connection Broker will not route connections to it) until the server is rebooted. After the server has rebooted, this setting will revert to Allow All Connections.

Choose the option that suits your needs and click OK.

To change user logon mode from the command prompt, you'll use the change logon command. You must execute this command from the server whose user logon mode you're changing; the tool does not offer a remote option. The change logon syntax is pretty simple.

  • /query: Returns the state of the server
  • /enable: Enables logons that had been disabled
  • /disable: Disables all incoming connections, including reconnections
  • /drain: Puts the server into drain mode
  • /drainuntilrestart: Puts the server into temporary drain mode (until the system is restarted)

If you're familiar with this tool from previous versions of Windows Server, you might notice the options for enabling drain mode and temporary drain mode. Otherwise, the syntax hasn't changed since Windows Server 2003.

Notice that change logon offers an option that RD Session Host Configuration does not: /disable. Drain mode prohibits new connections but does allow users to reconnect to existing sessions. If you're serious about removing users from the server, use change logon /disable to prevent any incoming connections, even reconnections. However, use this option with care. Disabling logons when users have existing sessions open can result in lost data or profile changes in the orphaned sessions. Drain mode, combined with reminders to users that you will be shutting down the server and requests to users to log off their sessions, is a safer option.

Each of these options allows you to configure only one server, though. To set the logon mode on more than one server at a time, use either Group Policy or script the logon mode via WMI. To edit the User Logon Mode via Group Policy, go to Computer Configuration | Policies | Administrative Templates | Windows Components | Remote Desktop Services | Remote Desktop Session Host | Connections | Allow Users To Connect Remotely Using Remote Desktop Services.

Group Policy is most useful for longer-term changes affecting many servers (you wouldn't edit Group Policy for a temporary change to two servers), whereas WMI is better for faster or more directed changes. Group Policy isn't practical for, say, changing the logon mode for two RD Session Host servers in the farm while the other two keep accepting logons, but WMI works well for this.

One way to check for the current logon mode via WMI on the local computer is to run the following Windows PowerShell script. (To run this script on a remote computer, replace the value of $strComputer with the name of the other computer.)

$strComputer = "."
$RDSH = get-wmiobject -class "Win32_TerminalServiceSetting" -namespace
    "root\CIMV2\terminalservices" `
-computername $strComputer
switch ($RDSH.AllowTSConnections)
{
    0 {"User logons are disabled."}
    1 {"User logons are enabled."}
    default {"The user logon state cannot be determined."}
}
switch ($RDSH.SessionBrokerDrainMode)
{
    0 {"Allow all connections."}
    1 {"Allow incoming reconnections but prohibit new connections."}
    2 {"Allow incoming reconnections but until reboot prohibit new connections."}
    default {"The user logon state cannot be determined."}
}

For example, this script will return the following message if the server is in temporary drain mode.

User logons are enabled.
Allow incoming reconnections but until reboot prohibit new connections.

Notice that this script has to query two properties to return all the information. The AllowTSConnections property corresponds to the /enable and /disable switches, and SessionBrokerDrainMode corresponds to the /drain and /drainuntilrestart switches. As before, you are using the switch statement to evaluate the actual values and make interpreting the output easier. The efficiency of running a script to get the information you need is somewhat reduced if you have to look up the return values on MSDN to know what they mean.

[Previous] [Contents] [Next]