Windows OS Hub
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux

 Windows OS Hub / Exchange / How to Enable Maintenance Mode on Exchange Server

March 12, 2024

How to Enable Maintenance Mode on Exchange Server

In this article, we’ll show you how to properly put an Exchange Server 2019/2016 host into maintenance mode. You must put your Database Availability Group (DAG) into maintenance mode if you are going to install updates on an Exchange Server host (Windows Updates or Exchange CU) or maintain your server hardware. When you enable maintenance mode, you must move active databases off the Exchange server and switch the queue to other servers.

The Exchange Server has two built-in PowerShell scripts for managing maintenance mode:

  • StartDagServerMaintenance.ps1 – allows to move active databases and the Primary Active Manager (PAM) role to another server, and blocks the reverse migration of mailbox databases till the maintenance is over;
  • StopDagServerMaintenance.ps1 – allows you to take the Exchange server out of maintenance mode by performing the reverse procedures.

These scripts are located in the Scripts folder (CD $ExScripts) of the Exchange installation directory. The following syntax is used:

.\StartDagServerMaintenance.ps1 -ServerName <ServerName> -MoveComment Maintenance -PauseClusterNode
.\StopDagServerMaintenance.ps1 -serverName <ServerName>

These scripts enable you to automate some operations. In most cases, Exchange administrators prefer to manually put the server into maintenance mode.

There is an example of a PowerShell script you can use to enable the maintenance mode for your Exchange server. Run the commands on a computer with the Exchange Management Shell and the RSAT-Clustering module installed:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
Import-Module FailoverClusters

Or you can connect to your Exchange Server remotely using PowerShell:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://munexh01.woshub.com/PowerShell/ -Authentication Kerberos -Credential (Get-Credential)
Import-PSSession $Session

Set the names of your Exchange servers:
# a server that you want to enable the maintenance mode for
$maintance_srv = "munexh01.woshub.com"
# a target server you want to move mail queues to
$target_srv = "munexh02.woshub.com"
# Disable the HubTransport component of the server and put it into Draining mode
Set-ServerComponentState $maintance_srv –Component HubTransport –State Draining –Requester Maintenance
Restart-Service MSExchangeTransport
# Check that the HubTransport status has changed to Draining
Get-ServerComponentState -Identity $maintance_srv -Component Hubtransport

Exchnage Server HubTransport status Draining

If you run Get-ServerComponentState -Identity $maintance_srv now, all Exchange components (except Monitoring and RecoveryActionsEnabled) will have the Inactive status.

# Move mail queue to another server
Redirect-Message -Server $maintance_srv -Target $target_srv
# Make sure that the mail queue have been cleared:
Get-Queue
# Pause your cluster node. This will move the Primary Active Manager (PAM) role to another DAG host
Suspend-ClusterNode –Name $maintance_srv
# Move all the mounted copies of mailbox databases to other servers
Set-MailboxServer $maintance_srv –DatabaseCopyActivationDisabledAndMoveNow $true
# Prevent a database activation on the server
Set-MailboxServer $maintance_srv –DatabaseCopyAutoActivationPolicy Blocked

Wait until the mailbox databases are successfully moved to another host (this will take a few minutes). Make sure that the list of mounted databases on the server is empty:

Get-MailboxDatabaseCopyStatus -Server $maintance_srv | where {$_.Status -like "Mounted"}
# Put Exchange components into maintenance mode
Set-ServerComponentState $maintance_srv –Component ServerWideOffline –State InActive –Requester Maintenance
# Check if the server is in maintenance mode
Get-ServerComponentState -Identity $maintance_srv -Component ServerWideOffline
Get-MailboxDatabaseCopyStatus

Now you can complete the maintenance procedures for the Exchange host that you need. After you have done everything on the server, you need to perform the reverse steps to bring your Exchange Server host out of maintenance mode:

Set-ServerComponentState $maintance_srv –Component ServerWideOffline –State Active –Requester Maintenance
# You may check the status as shown below (it must change to Active):
Get-ServerComponentState $maintance_srv -Component ServerWideOffline

Get-ServerComponentState ServerWideOffline

Resume-ClusterNode –Name $maintance_srv
Set-MailboxServer $maintance_srv –DatabaseCopyAutoActivationPolicy Unrestricted
Set-MailboxServer $maintance_srv –DatabaseCopyActivationDisabledAndMoveNow $false
Set-ServerComponentState $maintance_srv –Component HubTransport –State Active –Requester Maintenance

Check the Exchange Server status:

Test-ServiceHealth $maintance_srv

Rebalance your active mailbox databases across DAG hosts according to the configured activation preferences using RedistributeActiveDatabases.ps1:

cd $exscripts
.\RedistributeActiveDatabases.ps1 -DagName mun-dag –BalanceDbsByActivationPreference

If you want to move all active copies of mailbox databases from one server to another, run the command below:

Move-ActiveMailboxDatabase -Server $target_srv -ActivateOnServer $maintance_srv -Confirm:$false

Perform a MAPI availability check:

Test-MAPIConnectivity -Server $maintance_srv

Check database statuses and replication in the DAG:

Get-MailboxDatabaseCopyStatus
Test-ReplicationHealth -DatabaseAvailabilityGroup

0 comment
4
Facebook Twitter Google + Pinterest
ExchangePowerShellWindows Server 2016Windows Server 2019
previous post
How to Disable TLS 1.0 and TLS 1.1 in Windows Using GPO
next post
How to Find the Source of Account Lockouts in Active Directory

Related Reading

Outlook Keeps Asking for Password on Windows

March 17, 2024

How to Block Sender Domain or Email Address...

March 17, 2024

Get a List of Mailboxes a User Has...

March 15, 2024

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

March 17, 2024

How to Manually Configure Exchange or Microsoft 365...

March 17, 2024

Fix: Microsoft Outlook Search Not Working on Windows...

March 17, 2024

How to Delete or Rename Default Mailbox Database...

March 17, 2024

Send Emails with Microsoft Graph API and PowerShell

March 17, 2024

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Encrypt Any Client-Server App Traffic on Windows with Stunnel

    June 12, 2025
  • Failed to Open the Group Policy Object on a Computer

    June 2, 2025
  • Remote Desktop Printing with RD Easy Print Redirection

    June 2, 2025
  • Disable the Lock Screen Widgets in Windows 11

    May 26, 2025
  • Configuring Windows Protected Print Mode (WPP)

    May 19, 2025
  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Outlook Keeps Asking for Password on Windows
  • How to Manually Configure Exchange or Microsoft 365 Account in Outlook 365/2019/2016
  • Search and Delete Emails from User Mailboxes on Exchange Server (Microsoft 365) with PowerShell
  • How to Cleanup, Truncate or Move Log Files in Exchange Server 2013/2016/2019?
  • Fix: Microsoft Outlook Search Not Working on Windows 10/11
  • Export Exchange or Office 365 Global Address List (GAL) to CSV
  • Configure Auto-Reply (Out of Office) Message in Exchange and Microsoft 365
Footer Logo

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


Back To Top