I had to patch many servers in a Exchange DAG (CU22, SU, etc.) and wanted to script the entire process cleanly to save time and standardize it.
Here’s my script, which I wrote to cleanly put the server into maintenance mode. I also took into account the possibility of moving emails in the mail queues to another server. The script also waits until all databases are unmounted. Finally, it checks again to ensure the server is indeed in maintenance mode (database and cluster node checkup).
IMPORTANT:
My script requires a redirect server to be specified, which will take over the existing message queue of the server being maintained. This server must be specified as a fully qualified domain name (FQDN) and must not itself be undergoing maintenance.
NOTICE:
I disable certain security features on the server during maintenance mode to ensure that updates install without problems. The first script disables the security features, and the second script re-enables them when maintenance mode is exited.
Please double-check afterward.
Script to enter maintenance mode
Script to exit the maintenance mode
I do NOT automatically revert the databases to their original master. Instead, I let the automatic PreferenceMoveFrequency handle it (default: 1 hour).
You can query the PreferenceMoveFrequency using the following command:
Get-DatabaseAvailabilityGroup | Format-Table Name, Preference*Or you can use my re-balancing Powershell script from here: