To do a proper Exchange Server maintenance without interruption when using a Database Availability Group (DAG) you have to go through a few steps within Exchange Management Shell. Start the Shell with admin privileges.

Activate maintenance mode

1. Define variables

$serverMaintenance = $env:COMPUTERNAME
$serverTarget = (Get-ExchangeServer | ? { $_.Name -ne $env:COMPUTERNAME } | select -First 1).Fqdn

2. Redirect messages

Set-ServerComponentState $serverMaintenance -Component HubTransport -State Draining -Requester Maintenance
Restart-Service MSExchangeTransport
Restart-Service MSExchangeFrontEndTransport
Redirect-Message -Server $serverMaintenance -Target $serverTarget -Confirm:$false

3. Suspend Cluster Node

Suspend-ClusterNode $serverMaintenance

4. Disable Database copy activation and initiate database move
This step may take some time, so wait here 2-5 minutes before proceeding to next step.

Set-MailboxServer $serverMaintenance -DatabaseCopyActivationDisabledAndMoveNow $True
Set-MailboxServer $serverMaintenance -DatabaseCopyAutoActivationPolicy Blocked

5. Verify if no database is mounted on the current server
Important: Wait until the output of that command is empty.

Get-MailboxDatabaseCopyStatus -Server $serverMaintenance | Where {$_.Status -eq "Mounted"}

6. Put all components to maintenance mode
Important: If you configured your loadbalancer properly with a healthcheck to the healthcheck.htm of each VDir, the services should be taken offline automatically as after this command healthcheck.htm does not return 200 OK anymore.

Set-ServerComponentState $serverMaintenance -Component ServerWideOffline -State Inactive -Requester Maintenance

7. Verify component state
Verify that all components except Monitoring and RecoveryActionsEnabled are listed as inactive.

Get-ServerComponentState $serverMaintenance | ft Component,State –Autosize

Cumulative Update procedure

1. Stop services
If you’re using POP3 and/or IMAP4 I would recommend to stop these services that no connetions are made to them:

Set-Service MSExchangePop3 -StartupType Disabled
Stop-Service MSExchangePop3 -Force
Set-Service MSExchangeIMAP4 -StartupType Disabled
Stop-Service MSExchangeIMAP4 -Force

2. Remove any UM language packs

Setup.exe /RemoveUMLanguagePack:de-de

3. .NET compatibility check
If your maintenance is because of an CU update, always check the .NET dependencies in the Microsoft Exchange Compatibility Matrix. If you need to upgrade .NET then first do that and reboot the machine.

4. Disable Software components
Some Software locks exchange files, therefore it’s necessary to stop/unload Antivirus software and also disable Backup Software and 3rd party Exchange Antivirus Solutions during update.

5. Check if CU Update needs Schema Update
If a Schema Update is necessary, you usually need the roles Schema Admins, Enterprise Admins and Domain Admins

setup.exe /PrepareAD /IAcceptExchangeServerLicenseTerms

6. Start CU Update
Mount the ISO, open a PowerShell window with administrative privileges.
Set the execution policy to unrestricted and start the upgrade:

Set-ExecutionPolicy Unrestricted
.\Setup.exe /IAcceptExchangeServerLicenseTerms /Mode:Upgrade 

7. Reboot the server

Restart-Computer -Force 

8. Install UM Language Packs from the Current CU
If you had to uninstall the language packs you now have to reinstall them. Always run the setup with administrative privileges.

9. Post CU Update

  • Switch back the Execution Policy to the desired value.
  • Check the Windows Services and Event Log, if everything looks fine start with the resume from maintenance procedure
  • Start disabled services from Antivirus, Backup,… again

Resume from maintenance mode

1.Re-enable services
If you had disabled IMAP4 and/or POP3 reactivate them

Set-Service MSExchangePop3 -StartupType Automatic
Start-Service MSExchangePop3 -Force
Set-Service MSExchangeIMAP4 -StartupType Automatic
Start-Service MSExchangeIMAP4 -Force

2. Re-activate server components

Set-ServerComponentState $env:COMPUTERNAME -Component ServerWideOffline -State Active -Requester Maintenance

3. Resume cluster node

Resume-ClusterNode $env:COMPUTERNAME

4. Re-enable Database Copy activation

Set-MailboxServer $env:COMPUTERNAME -DatabaseCopyActivationDisabledAndMoveNow $False
Set-MailboxServer $env:COMPUTERNAME -DatabaseCopyAutoActivationPolicy Unrestricted

5. Re-enable Hub transport

Set-ServerComponentState $env:COMPUTERNAME -Component HubTransport -State Active -Requester Maintenance
Restart-Service MSExchangeTransport
Restart-Service MSExchangeFrontEndTransport

6. Verify Server component state
Except ForwardSyncDaemon and ProvisioningRps every component should have the status Active.

Get-ServerComponentState $env:COMPUTERNAME | ft Component,State –Autosize 

7. Post maintenance resume checks

  • Check the Event Log for uncommon errors and warnings
  • Check if all services necessary are up and running
  • Check the database health
  • Make some connection tests (OWA / ECP)

8. Redistribute mailbox databases

cd $exscripts
.\RedistributeActiveDatabases.ps1 -DagName DAG -BalanceDbsBy ActivationPreference