Put Exchange Server in maintenance mode

Before updating the Exchange Server, it is recommended to put the Exchange Server in maintenance mode. We can put the Exchange Server in maintenance mode with some PowerShell commands. In this article, we have two Exchange Servers. The names of the Exchange Servers are EX01 and EX02. We will place Exchange Server EX01 in maintenance mode.

Table of contents

Put Exchange Server in maintenance mode

Login on the Exchange Server EX01. Run Exchange Management Shell as administrator. Set the Hub Transport Service to draining. It will stop accepting any more messages.

[PS] C:\>Set-ServerComponentState -Identity "EX01" -Component HubTransport -State Draining -Requester Maintenance

Copy

Redirect any queued messages to EX02. The target Server value has to be the target server’s FQDN. The target server shouldn’t be in maintenance mode.

[PS] C:\>Redirect-Message -Server "EX01" -Target "EX02.alitajran.local"

Confirm
Are you sure you want to perform this action?
Redirecting messages to "EX02.alitajran.local".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "Y"): Y

Copy

If the server is a DAG member, run the following commands. If your server is not a DAG member, skip to the command for setting ServerWideOffline.

Pause the cluster node. Suspend Server EX01 from the DAG.

[PS] C:\>Suspend-ClusterNode "EX01"

Name       ID    State
----       --    -----
EX01       1     Paused

Copy

Disable database copy automatic activation. This command will also move any active database copies to other DAG members. Assuming there are other healthy DAG members available. This is not instantaneous, and it can take several minutes for the moves to occur. We’ll check it in one of the following commands.

[PS] C:\>Set-MailboxServer "EX01" -DatabaseCopyActivationDisabledAndMoveNow $true

Copy

Make a note of the database copy automatic activation policy on the server. You can set it back to this value at the end of maintenance. The default setting is Unrestricted.

[PS] C:\>Get-MailboxServer "EX01" | Select DatabaseCopyAutoActivationPolicy

DatabaseCopyAutoActivationPolicy
--------------------------------
                    Unrestricted

Copy

Set it to Blocked to prevent any of the databases from becoming Active.

[PS] C:\>Set-MailboxServer "EX01" -DatabaseCopyAutoActivationPolicy Blocked

Copy

Check for any database copies that are still mounted on the server. It may take a while for the Active databases to move. This command should return no results. If any database copies are still active on the server and other DAG members host copies of the database, perform a manual switchover.

[PS] C:\>Get-MailboxDatabaseCopyStatus -Server "EX01" | Where {$_.Status -eq "Mounted"}

Copy

Once the active databases have been moved, we will check the transport queue. Queues should be empty or almost empty, as we will be disabling all server components. Any emails still pending in the queues will have a delay in delivery until the server is taken out from maintenance mode.

[PS] C:\>Get-Queue

Identity        DeliveryType               Status MessageCount Velocity RiskLevel OutboundIPPool NextHopDomain
--------        ------------               ------ ------------ -------- --------- -------------- -------------
EX01\4          SmtpDeliveryToMailbox      Ready  0            0        Normal    0              db2
EX01\8          SmtpDeliveryToMailbox      Ready  0            0        Normal    0              db4
EX01\15         SmartHostConnectorDelivery Ready  0            0        Normal    0              mx1.spambull.com
EX01\20         SmtpDeliveryToMailbox      Ready  0            0        Normal    0              db5
EX01\22         SmartHostConnectorDelivery Ready  0            0        Normal    0              mx2.spambull.com
EX01\Submission Undefined                  Ready  0            0        Normal    0              Submission
EX01\Shadow\3   ShadowRedundancy           Ready  0            0        Normal    0              ex02.alitajran.local

Copy

Put the Server EX01 into maintenance mode.

[PS] C:\>Set-ServerComponentState "EX01" -Component ServerWideOffline -State Inactive -Requester Maintenance

Copy

Check the load balancer

Do you have the Exchange Server configured in a load balancer? Verify that the load balancer health checks have taken the server out of the pool or marked it as offline/inactive. If the load balancer does not automatically do this, manually mark the server as offline/inactive. Log into your load balancer and set any virtual services you have to disable any connections to Server EX01. Typically there would be SMTP and HTTPS virtual services. This will force any future connections to Server EX01.

How to verify Exchange Server is in maintenance mode

Verify if the Exchange Server EX01 has been placed into maintenance mode. All components should show Inactive except for Monitoring and RecoveryActionsEnabled.

[PS] C:\>Get-ServerComponentState "EX01" | Select Component, State

Component                     State
---------                     -----
ServerWideOffline          Inactive
HubTransport               Inactive
FrontendTransport          Inactive
Monitoring                   Active
RecoveryActionsEnabled       Active
AutoDiscoverProxy          Inactive
ActiveSyncProxy            Inactive
EcpProxy                   Inactive
EwsProxy                   Inactive
ImapProxy                  Inactive
OabProxy                   Inactive
OwaProxy                   Inactive
PopProxy                   Inactive
PushNotificationsProxy     Inactive
RpsProxy                   Inactive
RwsProxy                   Inactive
RpcProxy                   Inactive
UMCallRouter               Inactive
XropProxy                  Inactive
HttpProxyAvailabilityGroup Inactive
ForwardSyncDaemon          Inactive
ProvisioningRps            Inactive
MapiProxy                  Inactive
EdgeTransport              Inactive
HighAvailability           Inactive
SharedCache                Inactive
MailboxDeliveryProxy       Inactive
RoutingUpdates             Inactive
RestProxy                  Inactive
DefaultProxy               Inactive
Lsass                      Inactive
RoutingService             Inactive
E4EProxy                   Inactive
CafeLAMv2                  Inactive
LogExportProvider          Inactive

Copy

Before starting with the updates, I recommend rebooting the Exchange Server first. This will free up resources and clear any pending updates. After the reboot, you can start installing the updates.Do you like to know how to take the Exchange Server out of maintenance mode? Read the following article.

Conclusion

In this article, you learned how to place the Exchange Server in maintenance mode with PowerShell. You can perform upgrades and updates during business hours without disrupting any clients. It’s good to have a list of PowerShell commands before starting.

Archives