The Script
I wrote this script for a company with 8 sites and 8 different DAGs. Their DAGS are site specific with 2 servers in the primary physical site (like Miami) and 2 more servers in a DR site (Like Minneapolis). This script will look at each database by DAG and check to see if the mounted copy has an Activation Preference of 1.
cls $dag = Get-DatabaseAvailabilityGroup foreach ($line in $dag) { $dagname = $line.name write-host "Examining the Database Availability Group $dagname" -ForegroundColor Yellow # Get each database in each DAG $ap = (Get-MailboxDatabase | where {$_.MasterServerOrAvailabilityGroup -eq $dagname}) # Loop for each DAG foreach ($line in $ap) { $server = $line.server $database = $line.name $set = $line.ActivationPreference foreach ($line2 in $set) { # normalize variables for later use $value = $line2.value $server = $line2.key # Find the database copy with an Activation Preference of 1 if ($line2.value -eq "1") { write "Server $server with database $database has the activation preference of $value" # Find the mounted copy of the database $mounted = get-mailboxdatabase $database $currentserver = $mounted.server.name # Check to see if the copy mounted has an Activation Preference of 1 if ($server -ne $currentserver) { write-host "The server " -nonewline -foregroundcolor Cyan write-host $currentserver -nonewline -foregroundcolor Red write-host " is not the correct server. Please move the database to " -nonewline -foregroundcolor Cyan write-host $server -nonewline -foregroundcolor Red write-host " " } } } } write-host " " }
For the same client, I ran the script as a check after they had performed some maintenance over a patch weekend. Here is what we saw:
Notice the red color in the results. These show that the above database is mounted on the wrong server. Listed in the line is where the DB is now and what server should be hosting it.
To fix the balance of these databases, you would run the ‘RedistributeActiveDatabases.ps1’ script that is in the Scripts directory on your Exchange server. The entire command would look something like this:
.\'RedistributeActiveDatabases.ps1 -DagName DAG01-S03 -BalanceDbsByActivationPreference -ShowFinalDatabaseDistribution -Confirm:$false
This puts our databases back the way we want and if I were to run the check again, I would see no more red:
That’s it. Easy way to troubleshoot and fix any database imbalance in your Exchange environment.
** Please note –> This has only been tested in an Exchange 2010 SP3+ environment so far