Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Windows Server 2016 / Setting Remote Desktop Drain Mode on a Windows Server RDS Host

October 3, 2022 PowerShellWindows Server 2016Windows Server 2019

Setting Remote Desktop Drain Mode on a Windows Server RDS Host

You can use RDS Drain Mode to maintain terminal hosts in a Remote Desktop Services farm. If you enable Drain Mode for your RDS server, you can prevent the server from accepting new user’s RDP connections, and current RD connections will stay active till users log off manually or automatically by the RDS session timeout. Then you will be able to maintain your Windows Server host without interrupting your RDS farm operation (install updates, change server or app settings, update configuration files, etc.).

Contents:
  • What Is Drain Modes on Windows Server Remote Desktop Services?
  • How to Deny New User Logons to an RD Session Server?
  • Set Drain Mode for Windows Server RDS Host via PowerShell

What Is Drain Modes on Windows Server Remote Desktop Services?

The Drain Mode appeared in Windows Server 2008 (Terminal Services Server Drain mode). When you put an RDS host in drain mode, it can no longer accept new user’s connections. As a rule, the mode is used when a server administrator needs to maintain a server (install Windows updates, configure or update apps) without affecting the availability of the entire RDS farm. An RDS host can work in either of the three types of the Drain Mode:

  • Allow All Connections (a default mode) — an RD Session Host accepts new connections;
  • Allow Reconnections, but Prevent New Logons — users are allowed to reconnect to existing sessions, but new sessions are not allowed. If you restart a server, users won’t be able to connect to it;
  • Allow Reconnections, but Prevent New Logons until the Server Is Restarted – this mode is similar to the previous one, but after the restart, the user logon mode is reset to Allow All Connections.

How to Deny New User Logons to an RD Session Server?

You can enable the Drain Mode on your RDS host server via the RDS collection settings.

  1. Open Server Manager -> All Servers -> and add all RDS servers of the farm;
  2. Select Remote Desktop Services on the left panel in the Server Manager. Select the RDS Collections;
  3. In the HOST SERVERS section, select a server you want to enable the Drain Mode for and select Do not allow new connections in the context menu.

rds collection properties -> do not allow new connections

Users having active Remote Desktop sessions will be able to reconnect to the server, while all new connections will be forwarded by the RD Connection Broker to other hosts in your RDS farm.

You can also set the Drain Mode locally on the RDS host via the command prompt. To do it, the change logon command is used.

change logon command on windows server 2016 rds host

To prevent new user connections, run the command below:

change logon /drain

Drain Mode RDS: New user logons are DISABLED, but reconnections to existing sessions are ENABLED

New user logons are DISABLED, but reconnections to existing sessions are ENABLED

Now, if a new user tries to connect to the RDS host directly (when the RD Connection Broker is not used), the following error appears:

Remote logins are currently disabled.

Remote logins are currently disabled.
At the same time an event with the Event ID 1070 and TerminalServices-RemoteConnectionManager as the source appears in the RDS host log:

A logon request was denied because the RD Session Host server is currently in drain mode and therefore not accepting new user logons. To configure the server to allow new user logons, use the Remote Desktop Services Configuration tool.

The following command enables the Drain Mode until the host restart:

change logon /drainuntilrestart

To prevent users even with active sessions to connect to the host, run this command:

change logon /disable

Session logins are currently DISABLED
If you are connected to the Remote Desktop Session Host in the client session mode, and disabled access using the command above and logged off (logoff.exe), you will be able to connect to the server through the console only (mstsc /admin).

To allow connections, use this command:

change logon /enable

To make sure if the Drain Mode is enabled on your RDS server, run the command below:
change logon /query

Session logins are currently ENABLED

drain mode Session logins are currently ENABLED
If you tried to set the Drain Mode on your server using change logon and see the following error:

Connections are currently ENABLED by Group Policy for this machine, unable to change.

Connections are currently ENABLED by Group Policy for this machine, unable to change

This means that the Drain Mode is configured via the GPO. The policy setting is called Allow users to connect remotely using Remote Desktop Services and you can find it under the following GPO section: Administrative Templates -> Windows Components -> Remote Desktop Services -> Remote Desktop Session Host -> Connections.

Group Policy: Allow users to connect remotely using Remote Desktop Services

Disable the policy or set it to Not Configured.

Set Drain Mode for Windows Server RDS Host via PowerShell

You can manage Drain Mode settings of an RDS host collection or a standalone RDS server using PowerShell:

Import-Module RemoteDesktop
# To deny new RDP connections to the Remote Desktop Services Host
Set-RDSessionHost -SessionHost mun-saprdsh1.woshub.com -NewConnectionAllowed No -ConnectionBroker mun-saprdcb.woshub.com

# To allow connections
Set-RDSessionHost -SessionHost mun-saprdsh1.woshub.com -NewConnectionAllowed Yes -ConnectionBroker mun-saprdcb.woshub.com

If you enable or disable the Drain Mode, the values of the following register parameters are changed:

  • WinStationsDisabled HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\
  • TSServerDrainMode HKLM\System\CurrentControlSet\Control\Terminal Server\

WinStationsDisabled and TSServerDrainMode registry parameters for RDS Drain Mode

For example, when the Drain mode is enabled, the registry values are set to WinStationsDisabled = 0 and TSServerDrainMode = 2.

You can also make sure if the Drain Mode on your host is enabled using the PowerShell script below:

Get-WmiObject win32_terminalservicesetting -N "root\cimv2\terminalservices" | %{
if ($_.logons -eq 1){
"Disabled"}
Else {
switch ($_.sessionbrokerdrainmode)
{
0 {"Enabled"}
1 {"DrainUntilRestart"}
2 {"Drain"}
default {"error"}
}
}
}

To enable the Drain Mode via PowerShell (similar to change logon /Drain):

$temp = (Get-WmiObject win32_terminalservicesetting -N "root\cimv2\terminalservices")
$temp.sessionbrokerdrainmode=2
$temp.put()

To put the RDS host to normal mode (change logon /enable), run this command:

$temp = (Get-WmiObject win32_terminalservicesetting -N " root\cimv2\terminalservices ")
$temp.sessionbrokerdrainmode=0
$temp.logons=0
$temp.put()

check drain mode on windows server 2016 rds host via powershell

2 comments
1
Facebook Twitter Google + Pinterest
previous post
Install and Configure SNMP on RHEL/CentOS/Fedor
next post
Dumping User Passwords from Windows Memory with Mimikatz

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

November 7, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

2 comments

Shlomi May 19, 2021 - 6:42 pm

Amazing. I have not hear about this option.
Thank you mate!

Reply
Paul March 4, 2023 - 9:45 pm

Disabling logons on a server locally doesn’t not update the Allow Logins flag on the broker. This is a server-based setting, not collections-based. This does give a more friend, “Remote logins are currently disabled” compared to the broker method which presents an error saying “There are no available computers in the pool. Try connecting again or contact your network administrator”.

They have the same effect though – no logins.

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configuring Port Forwarding in Windows
  • Manage Windows Updates with PSWindowsUpdate PowerShell Module
  • Start Menu or Taskbar Search Not Working in Windows 10/11
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • Adding Drivers into VMWare ESXi Installation Image
  • How to Hide Installed Programs in Windows 10 and 11
  • Configuring SFTP (SSH FTP) Server on Windows
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top