This is a great one liner in PowerShell that will allow you to get a listing of all the databases for your Exchange Server environment. It will also tell you if those databases are on their preferred node in the DAG and whether they are actively mounted on that node.
This is helpful to know if you have multiple database fail-overs and need to know which databases are where so that you can re-balance them properly. If you are in a large environment, this will help you get a handle on the issue and be able to remediate quickly.
1 | Write-Host;Date;Write-Host;Get-MailboxDatabase -Status | Sort Name | ForEach {$db=$_.Name; $xNow=$_.Server.Name ;$dbown=$_.ActivationPreference | Where {$_.Value -eq 1}; Write-Host $db "on" $xNow "Should be on" $dbOwn.Key "- STATUS:" -NoNewLine -ForeGroundColor Yellow; If ( $xNow -ne $dbOwn.Key){Write-host " NOT ON PREFERRED NODE" -ForegroundColor Red -NoNewLine; } Else {Write-Host " ON PREFERRED NODE" -ForegroundColor Green -NoNewLine}; If ( $_.Mounted -ne "True"){Write-host " & DISMOUNTED" -ForegroundColor Red; } Else {Write-Host " & MOUNTED" -ForegroundColor Green}} |
Here is an example of the output:
Now, that you have your listing of DBs and their status, you can run the following script from PowerShell to mount those DBs to their preferred nodes:
1 | Write-Host;Date;Write-Host;Get-MailboxDatabase -Status | Sort Name | ForEach {$db=$_.Name; $xNow=$_.Server.Name ;$dbown=$_.ActivationPreference | Where {$_.Value -eq 1}; Write-Host $db “on” $xNow “Should be on” $dbOwn.Key -NoNewLine -ForeGroundColor Yellow; If ( $xNow -ne $dbOwn.Key){Write-host ” NOT ON PREFERRED NODE” -ForegroundColor Red; Move-ActiveMailboxDatabase $db -ActivateOnServer $dbOwn.Key -confirm:$False -SkipClientExperienceChecks | ft -a -wr} Else {Write-Host ” ON PREFERRED NODE” -ForegroundColor Green -NoNewLine}; If ( $_.Mounted -ne "True"){Write-host " & DISMOUNTED" -ForegroundColor Red; } Else {Write-Host " & MOUNTED" -ForegroundColor Green}} |
Since SLA and remediation are big factors in reactive support, having these scripts help save the day when things get quirky in Exchange. Please comment and submit your scripts as well!