Blog Post

Exchange Team Blog
3 MIN READ

Preserving Activation Blocks After Performing DAG Member Maintenance

The_Exchange_Team's avatar
Apr 10, 2013

 

In Exchange 2010, when a database availability group (DAG) member needs service, it can be placed into maintenance mode. Exchange 2010 includes scripts the StartDagServerMaintenance.ps1 and StopDagServerMaintenace.ps1 scripts to place/remove a DAG member from maintenance mode. For a summary of what these scripts do, see this post.

Within a DAG, it is not uncommon to have one or more databases or servers blocked from automatic activation by the system. Some customers configure entire servers to be blocked from activation, some block individual copies, and some do a combination of both, based on their business requirements. Administrators using the maintenance mode scripts will find their configured activation blocks reset to the unblocked. This behavior is not a problem with the scripts; in fact, the scripts are working as designed.

Here is an example of a database copy that has had activation suspended:

[PS] C:\>Get-MailboxDatabaseCopyStatus DAG-DB0\MBX-2 | fl name,activationSuspended

Name                             : DAG-DB0\MBX-2
ActivationSuspended              : True

Here is an example of a server that has activation blocked:

[PS] C:\>Get-MailboxServer MBX-2 | fl name,databasecopyautoactivationpolicy

Name                             : MBX-2
DatabaseCopyAutoActivationPolicy : Blocked

When the administrator executes the stopDagServerMaintenance.ps1 script, these states are reset back to their defaults. Here is an example of the states post StopDagServerMaintenance.ps1:

[PS] C:\Program Files\Microsoft\Exchange Server\V14\Scripts>Get-MailboxDatabaseCopyStatus DAG-DB0\MBX-2 | fl name,activationSuspended

Name                             : DAG-DB0\MBX-2
ActivationSuspended              : False

[PS] C:\Program Files\Microsoft\Exchange Server\V14\Scripts>Get-MailboxServer MBX-2 | fl name,databasecopyautoactivationpolicy

Name                             : MBX-2
DatabaseCopyAutoActivationPolicy : Unrestricted

Although the maintenance scripts behavior is by design, it can lead to undesirable scenarios, such as lagged database copies being activated. Of course, to eliminate these issues, an administrator can record database and server settings before and after maintenance and reconfigure any reset settings as needed.

To help with this, here is a sample script I created that records database and server activation settings into a CSV file which can then be used with the maintenance scripts to adjust the states automatically.

Download: MaintenanceWrapper.ps1 attached to this post.

What the script does

When you run the script, it creates two CSV files (on the server you run it on) along with a transcript that contains the results of the command executed. The first CSV file contains all database copies assigned to the server and their activation suspension status. Here's an example:

#TYPE Selected.Microsoft.Exchange.Management.SystemConfigurationTasks.DatabaseCopyStatusEntry
"Name","ActivationSuspended"
"DAG-DB0\DAG-3","True"
"DAG-DB1\DAG-3","True"

The second CSV file contains the database copy auto activation policy of the server. For example:

#TYPE Selected.Microsoft.Exchange.Data.Directory.Management.MailboxServer
"Name","DatabaseCopyAutoActivationPolicy"
"DAG-3","Blocked"

Using maintenanceWrapper.ps1 to start and stop maintenance

Because this scipt is unsigned, you'll need to relax the execution policy on the server to allow for unsigned scripts.

IMPORTANT: Allowing unsigned PowerShell scripts to execute is a security risk. For details, see Running Windows PowerShell Scripts. If this option does not meet your organization's security policy, you can sign the script (requires a code-signing certificate).

This command sets the execution policy on a server to allow unsigned PowerShell scripts to execute:

Set-ExecutionPolicy UNSIGNED

You can use the maintenanceWrapper.ps1 script to start and stop maintenance procedure on a DAG member.

  1. Use this command to start the maintenance procedure:

    maintenanceWrapper.ps1 –server <SERVERNAME> –action START

    The command creates the CSV files containing the original database states and then invokes the StartDagServerMaintenance.ps1 script to place the DAG member in maintenance mode.

  2. After maintenance is completed, you can stop the maintenance procedure using this command:

    maintenanceWrapper.ps1 –server <SERVERNAME> –action STOP

    The command calls the StopDagServerMaintenance.ps1 script to remove the DAG member from maintenance mode and then resets the database and server activation states from the states recorded in the CSV file.

Give the script a try and see if it makes maintenance mode for activation-blocked servers and databases easier for you. I hope you find this useful, and I welcome any and all feedback.

*Special thanks to Scott Schnoll and Abram Jackson for reviewing this content and David Spooner for validating the script.

Tim McMichael

Updated Apr 29, 2020
Version 2.0
  • Excellent! We just ran into an issue with an off-site copy activating unexpectedly, and I was toying with the idea of writing a wrapper myself - now I won't have to!

    Thanks, Tim!

  • @Lars:

    Excellent!  Hopefully it will be helpful.

    TIMMCMIC

  • Great Article for us Exchange On-Premises customers.

    Thanks ;-) will use the .ps1 very soon

  • Very good Article for us Exchange On-Premises customers.

    I am seeing good Exchange On-Premises Articles these days in Exchange Team Blog ;-)

  • Wonderful!  I'm going to be deploying a lagged DB server and one DB at our DR site in the next few months, so this will become part of my normal DB server maintenance.  

  • Nice, but could really be built into the product

    ie another possible value like DatabaseCopyAutoActivationPolicy: AlwaysBlocked, that the scripts will not change. And something similar at the database level (would be trickier because that one is true/false)

  • Just thought i'd point out the syntax above is wrong.

    The correct syntax (as noted in the .ps1 notes) is:

    maintenanceWrapper.ps1 –server <SERVERNAME> –action START

    maintenanceWrapper.ps1 –server <SERVERNAME> –action STOP

    Thanks for the script -- works great!

  • @Jlong:

    Thanks for the catch in the syntax.  We're fixing the blog post now.

    TIMMCMIC