After you migrate the mailboxes to Microsoft 365/Office 365 and all the SMTP relay goes…
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.
Table of contents
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"
Confirm
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
DatabaseCopyAutoActivationPolicy
--------------------------------
Unrestricted
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 mx1.spambull.com
EX01-2019\20 SmtpDeliveryToMailbox Ready 0 0 Normal 0 db5
EX01-2019\22 SmartHostConnectorDelivery Ready 0 0 Normal 0 mx2.spambull.com
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; .\HealthChecker.ps1 -BuildHtmlServersReport -HtmlReportFile "ExchangeAllServersReport.html"; .\ExchangeAllServersReport.html
The below screenshot shows what Exchange Server Maintenance looks like in the Exchange Health Checker report.
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 »
Conclusion
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.
not everyone’s article is mentioned in the manufacturer’s recommendation… but yours is. Congratulations and Thank You for your posts!
https://learn.microsoft.com/en-us/answers/questions/1478120/maintenance-mode-for-exchange-2019-hybrid-servers
Hello ALI,
Very important topic and great explanation, so I even decided to automate it.
I hope that you don’t mind if I share it here.
https://ps1code.com/2024/02/05/pexmm/
Hi Roman,
Automation is always nice to see! Great job.
I have 3 Exchange servers 2 in DC site (MBX01 & MBX02) and 1 DR site (MBX03),all of them are in DAG.Can i put MBX01 & MBX02 site servers on Maintenance mode??
Is it recommended to Put 2 servers out of 3 into Maintenance Mode ???
Nice post and very useful! Your articles are very good! Keep on!
I would like to ask, if I do not have a load-balancer and only use DNS round-robin to do the load balancing part, is it still ok? It seems that user may have 50% directed to the Exchange node which is in maintenance mode and will fail to use mail.
Would you mind to comment on it?
When using round robin you need to delete the DNS A record for the server that you are putting into maintenance. When putting it out of maintenance, recreate the A record.
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.
Gil
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
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
You need to fix your internal DNS so that at a bare min your EX servers are doing round robin.
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! 🙂
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?
Hi Andrey,
Put the Exchange Server in maintenance mode.
There is a dedicated article on how to install Exchange Security Update.
Just went over your steps and it works like a charm. Thank you for the post, very helpful!
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
Why don’t you want to run all the commands?
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
It’s possible, and I have seen admins do that, but it’s not correct. The recommended way is to follow the steps in the article.
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.
Hi Mica,
I am happy to hear that you find the information useful. Thank you and enjoy!
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
The best practice is to put Exchange Server in maintenance mode before you update. Don’t forget to check for vulnerabilities after you finish updating.
how back active from maintenence?
You can read the article: Take Exchange Server out of maintenance mode
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 http://hir-exmb-01.yourdomain.com/PowerShell/ -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 can-exmb-03.yourdomain.com | 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
I will write about the script in one of the upcoming articles. When I do that, I will try out your script.
Excellent post !
Thank you. I am happy that you found it interesting.