How to Enable Maintenance Mode on Exchange Server? , Ranjan.info

In this article, we will show you how to properly put Exchange Server 2019/2016 host into maintenance mode. If you are going to install updates on the Exchange Server host (Windows Update or Exchange CU) or maintain your server hardware then you will need to put your Database Availability Groups (DAGs) into Maintenance Mode. When you enable maintenance mode, you must move the active databases from the Exchange server and switch the queues to other servers.

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

  • StartDagServerMaintenance.ps1 – Allows moving active databases and the primary Active Manager (PAM) role to another server, and prevents reverse migration of mailbox databases until maintenance is finished;
  • StopDagServerMaintenance.ps1 – Allows you to get Exchange Server out of maintenance mode by performing 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 certain tasks. In most cases, Exchange administrators prefer to manually put servers into maintenance mode.

Here is an example of a PowerShell script that you can use to enable maintenance mode for your Exchange server. On a computer with the Exchange Management Shell and the RSAT-clustering module installed, run the command:

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 -Authentication Kerberos -Credential (Get-Credential)
Import-PSSession $Session

Set the name of your Exchange Server:
# 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

if you run Get-ServerComponentState -Identity $maintance_srv Now, all Exchange components (except Monitoring and RecoveryActions) will be placed in an inactive state.

# 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 database is successfully moved to the other host (this will take a few minutes). Make sure 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

You can now perform the required maintenance procedures for the Exchange host. After you’ve done everything on the server, you’ll need to do the steps in reverse 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 Exchange Server Status:

Test-ServiceHealth $maintance_srv

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

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

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

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

Check MAPI availability:

Test-MAPIConnectivity -Server $maintance_srv

Check the status and replication of the database in the DAG:

Get-MailboxDatabaseCopyStatus
Test-ReplicationHealth -DatabaseAvailabilityGroup

Leave a Comment