skip to Main Content

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-2019 and EX02-2019. We will place Exchange Server EX01-2019 in maintenance mode.

Put Exchange Server in maintenance mode

Sign in to Exchange Server EX01-2019. 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-2019" -Component HubTransport -State Draining -Requester Maintenance

Redirect any queued messages to EX02-2019. 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-2019" -Target "EX02-2019.exoip.local"

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

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-2019 from the DAG.

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

Name      State  Type
----      -----  ----
EX01-2019 Paused Node

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-2019" -DatabaseCopyActivationDisabledAndMoveNow $true

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-2019" | Select DatabaseCopyAutoActivationPolicy


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

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

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-2019" | Where {$_.Status -eq "Mounted"} | ft -AutoSize

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-2019\4          SmtpDeliveryToMailbox      Ready  0            0        Normal    0              db2
EX01-2019\8          SmtpDeliveryToMailbox      Ready  0            0        Normal    0              db4
EX01-2019\15         SmartHostConnectorDelivery Ready  0            0        Normal    0    
EX01-2019\20         SmtpDeliveryToMailbox      Ready  0            0        Normal    0              db5
EX01-2019\22         SmartHostConnectorDelivery Ready  0            0        Normal    0    
EX01-2019\Submission Undefined                  Ready  0            0        Normal    0              Submission
EX01-2019\Shadow\3   ShadowRedundancy           Ready  0            0        Normal    0              ex02-2019.exoip.local

Put the Server EX01-2019 into maintenance mode.

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

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. Sign in to your load balancer and set any virtual services you have to disable any connections to Server EX01-2019. Typically there would be SMTP and HTTPS virtual services. This will force any future connections to Server EX01-2019.

How to verify Exchange Server is in maintenance mode

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

[PS] C:\>Get-ServerComponentState "EX01-2019" | 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

Another way to verify that Exchange Server is in maintenance mode is to download and run the Exchange Health Checker PowerShell script.

[PS] C:\scripts>Get-ExchangeServer | ?{$_.AdminDisplayVersion -Match "^Version 15"} | %{.\HealthChecker.ps1 -Server $_.Name}; .\HealthChecker.ps1 -BuildHtmlServersReport; .\ExchangeAllServersReport.html

The below screenshot shows what Exchange Server Maintenance looks like in the Exchange Health Checker report.

Put Exchange Server in maintenance mode script

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 Exchange Server Cumulative Update/Exchange Server Security Update.

Read more: Take Exchange Server out of maintenance mode »


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.

Did you enjoy this article? You may like Get mailbox database size and white space. Don’t forget to follow us and share this article.



ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 21 Comments

  1. Hey has anyone created a single powershell script file that contains all the commands that Ali gave us so we don’t have to ‘copy/paste’ each commands individually when running them to put exchange in maintenance mode?

    Like Excute Command Line 1 – pause – (technician verify on screen result no error – press enter for next command). If there is an error, then Control Z/C to cancel running the script. Almost like creating a BAT file.


  2. Hi Ali

    how do you redirect messages correctly in a DAG with 3 members and each one of the databases (2) of the member in maintenance mode is activated on one of the two othe DAG members?

    EX01 MDB01 MDB02 in Maintenace mode MDB01 -> Active on EX03 MDB02 – > Active on EXC02
    EX02 MDB03 MDB04
    EX03 MDB05 MDB06

  3. Ali Tajran – your steps is excellent – however, we have a small issue that appears random. Below is the info:
    (Exchange 2016 environment)

    We have Ex01 and Ex02 with DAG. When we put EX02 on maintenance mode, one of our MAJOR user complains that desktop Outlook 2016 is disconnected, however OWA is working.

    On my computer – my Outlook (both 2010 & 2016) on separate computers are working and never got disconnected.

    MAJOR user have same account setup (2016) as I do, we do have Cache Mode turned on.

    She have shut down outlook and restart – still saying disconnected.

    We are at witts end on figuring out why MAJOR user is affected so.

    P.S. on the last step to put the exchange in maintenance mode: we’ve added to restart following services on the exchange: Frontend Trasport and Transport

    Send direct email if you need to ask me more Q&A

  4. Now aside reading and following Paul Cunningham and other Exchange MVP and MCM blogs, your site currently is one under my radar. As junior engineer, i am still astonished on your detailed and meticulous articles, your methodology is on-par with MOC’s hands-on-labs, even a dummy can follow *LOL*.
    I hope you can also cover other MS related technologies such as Hyper-V, AD and HADR-related topics.
    God bless you man, your support for community shall be rewarded. I believe sooner or later you’ll be granted MVP badge, no doubt about that..aameen! 🙂

  5. Hi Ali,

    We have 2 Exchange Servers with DAG. I would like to deploy this April 2021 security patch. Do I need to bring the exchange server to maintenance mode, or can i just run the patch manually under administrator rights?

  6. Just went over your steps and it works like a charm. Thank you for the post, very helpful!

  7. I have to
    Make upgrade tomorrow i have two mailbox servers with DAG but i dont want to run the dag commands is this possible?
    My server is exchange 2016 and the update is CU 19

      1. To be honest it is a big client and i never tried that before and it is ok with him to shut down the servers so i ll shut a server and start updating the other one

  8. Hi ALI TAJRAN, thank you!!!!
    Recently, your site comes up whenever I need accurate and critical Exchange / Powershell info, especially with DAGs. And today, I needed a refresher for the maintenance mode topic, which I had to do live in front of a customer in a live prod environment while not appearing nervous — it all went well, so thank you for spending the time to document each step with explanations. Saved my weekend.

  9. Hi,

    If I have single on-prem exchange server, do I need to put it in maintenance mode, for example, when updating CUs or security patches or Monthly Tuesday patches?

    Thanks a lot

  10. I understand redirection of the email queues, but under “C:\Program Files\Microsoft\Exchange Server\V15\scripts\StartDagServerMaintenance.ps1” is the script to do the rest.

    here is my script, let me know of any suggestions….

    # if you are using your powershell ISE console on your workstation or server. Use only on $Session.
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Authentication Kerberos

    # Import $Session above; only one session can be imported. If errors, close PowerShell ISE and start over
    Import-PSSession $Session | Out-File -FilePath c:\temp\can-exmb-02.txt

    # before running the StartMaintenanceMode script
    Set-ServerComponentState can-exmb-02 -Component HubTransport -State Draining -Requester Maintenance | Out-File -FilePath c:\temp\can-exmb-02.txt -Append
    Start-Sleep -Seconds 10

    # restart transport service for each server
    Get-Service -ComputerName can-exmb-02 MSExchangeTransport | Restart-Service | Out-File -FilePath c:\temp\can-exmb-02.txt -Append
    Start-Sleep -Seconds 10

    # check transport service
    Get-Service -ComputerName can-exmb-02 MSExchangeTransport | Out-File -FilePath c:\temp\can-exmb-02.txt -Append
    Start-Sleep -Seconds 10

    # Redirect message queue (message queue is moved to another server)
    Redirect-Message -Server can-exmb-02 -Target | Out-File -FilePath c:\temp\can-exmb-02.txt -Append
    Start-Sleep -Seconds 10

    # Set component state
    Set-ServerComponentState can-exmb-02 -Component ServerWideOffline -State Inactive -Requester Maintenance | Out-File -FilePath c:\temp\can-exmb-02.txt -Append
    Start-Sleep -Seconds 10

    # check component state
    Get-ServerComponentState can-exmb-02 | ft Component,State -AutoSize | Out-File -FilePath c:\temp\can-exmb-02.txt -Append
    Start-Sleep -Seconds 15

    #check queues
    Get-Queue -Server can-exmb-02 | Out-File -FilePath c:\temp\can-exmb-02.txt -Append
    Start-Sleep -Seconds 10

    Move-ADObject ‘CN=can-EXMB-02,OU=Hiram Servers,OU=Servers,DC=yourdomain,DC=com’ -TargetPath ‘CN=computers,DC=yourdomain,DC=com’ | Out-File -FilePath c:\temp\can-exmb-02.txt -Append
    Start-Sleep -Seconds 10

    #change directory path
    $exscripts = “C:\Program Files\Microsoft\Exchange Server\V15\scripts”
    Set-Location $exscripts
    .\StartDagServerMaintenance.ps1 -serverName can-exmb-02 | Out-File -FilePath c:\temp\can-exmb-02.txt -Append

    #check servers in maintenace mode
    Get-databaseavailabilitygroup -status | fl name,ServersInMaintenance

Leave a Reply

Your email address will not be published. Required fields are marked *