Exchange 2010 SP1 includes a few new scripts that you can use to make DAG member maintenance a breeze. It's a simple process; you run a script to put a DAG member into maintenance mode, moving the active databases off the server. After maintenance has been completed, you run another script to take the server out of maintenance mode and then you can redistribute the databases across the DAG. The process is outlined in detail below.
1. Run the StartDagServerMaintenance.ps1 script to put the DAG member in maintenance mode
When you run this script, it moves all the active databases to other DAG members. It pauses the node in the cluster, and sets the DatabaseCopyAutoActivationPolicy mailbox server setting to Blocked. The Suspend-MailboxDatabaseCopy cmdlet is run for each database hosted by the DAG member, and the cluster core resources will be moved to another server in the DAG if needed.

2. Run the StopDagServerMaintenance.ps1 script to take the DAG member out of maintenance mode
After maintenance is complete, run this script to take the server out of maintenance mode. It will run the Resume-MailboxDatabaseCopy cmdlet for each database its hosting, resume the node in the cluster, and set the DatabaseCopyAutoActivationPolicy setting to Unrestricted.

You can run these scripts remotely from another server with the Exchange tools installed and specify the DAG member using the serverName parameter. Just make sure that the server you are running the scripts from has the Windows Failover Cluster Management tools installed.
3. Run RedistributeActiveDatabases.ps1 script to re-balance the active database copies across the DAG
Finally, you can run this script to redistribute the active mailbox databases across the DAG. There are two options for balancing active database copies within a DAG: by activation preference and by site and activation preference.

When using the BalanceDbsByActivationPreference parameter the script tries to move the databases to their most preferred copy based on activation preference, regardless of the AD site. If you use the BalanceDbsBySiteAndActivationPreference parameter, the script will attempt to active the most preferred copy and also try to balance them within each AD site.
There are a number of parameters that can be used with this script. Run get-help .\RedistributeActiveDatabases.ps1 for more details. Also, all of these scripts are documented in Managing Mailbox Database Copies and Managing Database Availability Groups on TechNet.





{ 3 trackbacks }
{ 3 comments… read them below or add one }
When I run this command I get the following error. Have you seen this before?
[PS] C:\apps\Exchange\Scripts>.\StartDagServerMaintenance.ps1 -serverName mbx01
WARNING: [18:42:24.717 UTC] Call-ClusterExe: cluster.exe did not succeed, but 5 was not a retry-able error code. Not
attempting any other servers. This may be an expected error by the caller.
WARNING: The Resume operation won’t have an effect on database replication because database ‘DB01′ hosted on server
‘MBX01′ is the active mailbox database.
WARNING: The Resume operation won’t have an effect on database replication because database ‘DB02′ hosted on server
‘MBX01′ is the active mailbox database.
WARNING: The Resume operation won’t have an effect on database replication because database ‘DB03′ hosted on server
‘MBX01′ is the active mailbox database.
WARNING: The Resume operation won’t have an effect on database replication because database ‘DB04′ hosted on server
‘MBX01′ is the active mailbox database.
Log-Error : [18:42:24.717 UTC] Start-DagServerMaintenance: Failed to suspend the server mbx01 from hosting the Primary
Active Manager, returned 5.
At C:\apps\Exchange\Scripts\StartDagServerMaintenance.ps1:165 char:14
+ Log-Error <<<< ($StartDagServerMaintenance_LocalizedStrings.res_0004 -f $serverName,$LastExitCode,"
tart-DagServerMaintenance") -stop
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Log-Error
It looks like cluster errors. Is you DAG/cluster in good heath? Here are some commands to check that:
Test-ReplicationHealth
Test-ServiceHealth
Got the same error. No idea, what this is. Try following:
Move-ActiveMailboxDatabase -Server <> -ActivateOnServer <>
This moves the mailbox database copies from Server1 to Server2.
Get-MailboxDatabaseCopyStatus -Server <>| Suspend-MailboxDatabaseCopy -ActivationOnly
This prevents the copies from Server 1 to be activated.
After the maintenance:
Get-MailboxDatabaseCopyStatus -Server <> | Resume-MailboxDatabaseCopy
.\RedistributeActiveDatabases.ps1 -DAGName DERT<> -BalanceDbsByActivationPreference -confirm:$false
Works fine for me.