Lost and Found DAG Databases

If you have a large amount of DAG databases you may want a quick way of identifying which Exchange mailbox role is hosting the active copy of your databases.  Sure you can take a look at the EMC but I have a quick way for you to determine if each database is mounted on the mailbox server specified with an activation preference of 1.  Credit for this script is to René van Maasakkers on his blog.

Start out with filtering down the databases that are part of a DAG and not recovery databases.  Then run a ForEach loop that will capture the name of the database, server on which the database is mounted, and the activation preference of the database.  Finally use Write-Host to enumerate the names grabbed earlier and use IF ELSE logic to output the status of the mounted database.


[powershell]
$DAGDbs = Get-MailboxDatabase | where {$_.mastertype -eq "DatabaseAvailabilityGroup" `
-and $_.recovery -ne "true"} | Sort ServerName,name

ForEach ($DAGDb in $DAGDbs){
$DBname=$DAGDb.Name
$DBmounted=$DAGDb.Server.Name
$AP1 = $DAGDb.ActivationPreference | Where {$_.Value -eq 1}

Write-Host $DBname “on” $DBmounted “Should be on” $AP1.key -NoNewLine;
If ($DBmounted -ne $AP1.Key){
Write-host ” WRONG” -ForegroundColor Red;
}Else{
Write-Host ” OK” -ForegroundColor Green
}
}
[/powershell]

Leave a Reply