As an Exchange Admin, running updates such as Security updates or Cumulative Updates are something we perform all the time as they are released. This may be in a test lab or dedicated dev environment so you can track any issues.

When servers are put into Maintenance Mode, no requests can go through to them. If for some reason you are performing an upgrade and the services start while the upgrade is busy, the end users connecting to that server will experience disconnect and reconnects or get popups which you want to avoid.

In this blog post, we will be covering how to put a server into Maintenance Mode and then take it out of Maintenance mode.

Enable Maintenance Mode

To put the Exchange server into maintenance mode, we need to run a few scripts from that Exchange Server or another one. If you are using Windows 2019 or Windows 2022 Server core, you need to first run two commands which is the following:

  • PowerShell (type in the command as is and press enter)
  • Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn (Load the Exchange 2019 Snapin)

Script

The scripts have two places that need updating, the server you are putting into maintenance mode (server1.fqdn) and the target server (server2.fqdn). Server2 will take the load from Server1. Here are the commands to run:

Set-ServerComponentState server1.fqdn -Component HubTransport -State Draining -Requester Maintenance
Restart-Service MSExchangeTransport
Restart-Service MSExchangeFrontEndTransport
Redirect-Message -Server server1.fqdn -Target server2.fqdn -Confirm:$False
Suspend-ClusterNode server1.fqdn
Set-MailboxServer server1.fqdn -DatabaseCopyActivationDisabledAndMoveNow $True
Get-MailboxServer server1.fqdn | Select DatabaseCopyAutoActivationPolicy
Set-MailboxServer server1.fqdn -DatabaseCopyAutoActivationPolicy Blocked
Set-ServerComponentState server1.fqdn -Component ServerWideOffline -State Inactive -Requester Maintenance
Get-ServerComponentState server1.fqdn | ft Component,State –Autosize

The last command displays the status of all the server components as shown below:

Quickly enable and disable maintenance mode in exchange 2019

Now that the server is in maintenance mode, you can run the security or cumulative update and reboot without it affecting anything. When you have rebooted the server and are ready to upgrade the next one, you need to take it out of maintenance mode.

Disable Maintenance Mode

With the server rebooted, we need to run the two commands again like we did when we enabled maintenance mode, here are the commands:

  • PowerShell (type in the command as is and press enter)
  • Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn (Load the Exchange 2019 Snapin)

SCRIPT

Here is the script to take the Exchange 2019 server out of maintenance mode and place it back into production:

Set-ServerComponentState server1.fqdn -Component ServerWideOffline -State Active -Requester Maintenance
Resume-ClusterNode server1.fqdn
Set-MailboxServer server1.fqdn -DatabaseCopyActivationDisabledAndMoveNow $False
Set-MailboxServer server1.fqdn -DatabaseCopyAutoActivationPolicy Unrestricted
Set-ServerComponentState server1.fqdn -Component HubTransport -State Active -Requester Maintenance
Set-ServerComponentState server1.fqdn -Component ForwardSyncDaemon -State Active -Requester HealthAPI
Set-ServerComponentState server1.fqdn -Component ProvisioningRps -State Active -Requester HealthAPI
Restart-Service MSExchangeTransport
Restart-Service MSExchangeFrontEndTransport
Get-ServerComponentState server1.fqdn | ft Component,State –Autosize

I added in the last command to check the server component state directly after enabling everything, you should see an output as shown below:

Quickly enable and disable maintenance mode in exchange 2019

You may now proceed to the next server if you have others and follow the same procedure, don’t forget to take a server out of maintenance mode when you are done with your upgrades.

Hope you find this helpful.

Discover more from Everything-PowerShell

Subscribe now to keep reading and get access to the full archive.

Continue reading