skip to Main Content

Put Exchange Server in maintenance mode

Before updating the Exchange Server, it is recommend 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.

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.

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.

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.

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, it can take several minutes for the moves to occur. We’ll check it in one of the following commands.

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.

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

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 there are other DAG members that host copies of the database, perform a manual switchover.

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 till the server is  taken out from maintenance mode.

Put the Server EX01 into maintenance mode.

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.

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.


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 with the PowerShell commands before starting. I hope that this article was informative to you. 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 4 Comments

  1. 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 *

Back To Top