Exchange Maintenance Mode

When you are performing maintenance in your Exchange environment it’s important to place the server in maintenance mode. This allows you to ensure that no users will be impacted by the maintenance that is being performed. I am always surprised at the number of people that don’t take the time to place their servers in MM before doing any work on them. The process really is pretty simple and can save you a ton of headaches in the event of an issue during maintenance.

When you place a server into maintenance mode the process will drain the transport queues. If it is a DAG member server, it will move the active copies of the DBs to another DAG member and ensure that no DBs can be mounted. And finally, it will place all the components to an inactive state. This process is the same for both Exchange 2013 and Exchange 2016. Exchange 2010 SP1 or later can be put in maintenance mode by using the StartDagServerMaintenance.ps1 script provided my Microsoft.

Put the server in maintenance mode

1. Drain the mail queues on the server.
[PS] C:\> Set-ServerComponentState EX16-1 -Component HubTransport -State Draining -Requester Maintenance
2. MS recommends restarting the transport services to help this change immediately take effect.
[PS] C:\> Restart-Service MSExchangeTransport
[PS] C:\> Restart-Service MSExchangeFrontEndTransport
3. Redirect pending messages to another Mailbox server.
[PS] C:\> Redirect-Message -Server EX16-1 -Target EX16-2.leenu.net
If the server is NOT a DAG member you can skip to step 8, otherwise we will continue to the DAG portion.
4. Pause the DAG node.
[PS] C:\> Suspend-ClusterNode EX16-1
5. Move all the active databases off of the server to another DAG member.
[PS] C:\> Set-MailboxServer EX16-1 -DatabaseCopyActivationDisabledAndMoveNow $True
6. Look at the status of the database auto activation policy. Keep this handy. We will need this when we take the server out of maintenance mode.
[PS] C:\> Get-MailboxServer EX16-1 | Select DatabaseCopyAutoActivationPolicy
If the policy is already set to Blocked you can skip step 7.
7. Block the server from hosting active database copies.
[PS] C:\> Set-MailboxServer EX16-1 -DatabaseCopyAutoActivationPolicy Blocked
8. Place the server in maintenance mode.
[PS] C:\> Set-ServerComponentState EX16-1 -Component ServerWideOffline -State Inactive -Requester Maintenance

Take the server out of maintenance mode

If your server is NOT a DAG member, perform steps 1, 5, and 6.
1. Take the server out of maintenance mode
[PS] C:\> Set-ServerComponentState EX16-1 -Component ServerWideOffline -State Active -Requester Maintenance
2. Unpause the DAG node.
[PS] C:\> Resume-ClusterNode EX16-1
3. Set the server to allow database copy activation
[PS] C:\> Set-MailboxServer EX16-1 -DatabaseCopyActivationDisabledAndMoveNow $False
4. Set the database auto activation policy back to its original setting. If it was set to blocked previously, leave it set that way. The default policy is Unrestricted
[PS] C:\> Set-MailboxServer EX16-1 -DatabaseCopyAutoActivationPolicy Unrestricted
5. Set the hub transport component back to active to allow it to accept connections.
[PS] C:\> Set-ServerComponentState EX16-1 -Component HubTransport -State Active -Requester Maintenance
6. Again, MS recommends that the transport services be restarted to help this change get picked up immediately.
[PS] C:\> Restart-Service MSExchangeTransport
[PS] C:\> Restart-Service MSExchangeFrontEndTransport
If the server was a DAG member and you moved all the active copies off of the server, you can easily move them back based on mount preference by running the RedistributeActiveDatabases.ps1 script provided by Microsoft.
[PS] C:\Program Files\Microsoft\Exchange Server\V15\Scripts> .\RedistributeActiveDatabases.ps1 -BalanceDbsByActivationPreference -Confirm:$false