Get Alert email when Exchange database is failed or/and not mounted on the preferred server (Activation Preference) ?!

When I design Exchange DAG deployment, i follow Microsoft recommendation on how to distribute databases across mailbox servers. Ross Smith did a great job explaining this concept and how to optimize this process.

THE CASE : Interesting fact

Whats next ? Suppose a database has activation preference on Mailbox server SRV1  = 1 , and another copy on mailbox server SRV2 with activation preference =2.

Normally, your database will be mounted on SRV1 and everyone is happy like my happiness when my favorite football team wins in El Classico game 🙂

Now, the database copy on SRV1 fails, and the database get automatically mounted on SRV2. Maybe it failed on SRV1 because the server restarted suddenly. But when SRV1 is back, guess what? the database will not go back to SRV1 !!

Well, we all love that it  automatically get mounted on SRV2 at least , but i guess we expect that when SRV1 gets up, that the database will return to SRV1. But Microsoft has a point here !

Microsoft point of view is that SRV1 may come up but still experiencing problems. So if Microsoft configures our expected behavior (that the database shall mount back to SRV1) , then the database will try to mount back, fail and then tries to mount again to SRV12, and then it will detect that SRV1 is up, and will try to get mounted there again…. A loop will happen simply. Got it ?!

Solution ? I guess the best solution here is to schedule a script that will run every one hour for example, and it will scan your DAG databases, and alert you via email if a database is not mounted on the mailbox server with Activation Preference =1. This way, you can manually investigate the issue , maybe check event logs , and manually decide to take action (mount the database back to the server with activation preference =1 )

Download Script

You can download it here :

Script Running Experience

As stated before, the script is meant to be run on a schedule to alert you via email when something needs alert. The script is designed for this purpose and will ONLY send email if something bad happens.

But if you want to download the script and run it quickly to evaluate it, then open your Exchange PowerShell console using an account with Exchange View Only Admin, and run it without any switches.

If all is fine, you will get notified that no actions are detected and no email to be sent .

DAG Database DAG Activation Preference Alert Email 3323

You will also get a red alert if something is wrong and an email is to be triggered.

DAG Database DAG Activation Preference Alert Email 3232

 Script breakdown 

The script will query all DAG databases in your environment using (Get-MailboxDatabase -STATUS | where {$_.MasterType -like “*DatabaseAvailabilityGroup*”}) command, and then will evaluate if there is any database not mounted on the Exchange mailbox server with activation preference = 1. If such database is found, an mail alert is sent. Else, nothing will happen. This is usefull if you want to schedule the script so you will receive email ONLY if something is not right.

The script also has a variable called ($AlertonFailure) that is set to false by default. If you open the script and manually set this variable to true, then the script will perform another test. It will search all DAG databases (only DAG database) and will send alert also if any of those databases are not mounted.


6 comments on “Get Alert email when Exchange database is failed or/and not mounted on the preferred server (Activation Preference) ?!

  1. If running as scheduled task with alert on, an email will be sent out every time the task is ran which won’t be ideal. It would be ideal if an alert can be sent out when the databases are not mounted or not on the preferred server and then another alert once the databases are mounted on the preferred server (may be utilizing start-sleep?)

  2. Great script. I’m trying to get something else but close. I want to make a script that queries all database copies (something like GetMailboxDatabaseCopyStatus *) and send email if it finds any copy or index that is not in healthy state,

  3. Basically what I intend to run is:
    Get-MailboxDatabaseCopyStatus * | Where {($_.Status -ne “Mounted”) -AND ($_.Status -ne “Healthy”) -OR ($_.ContentIndexState -ne “Healthy”)}
    and if any value is returned should be sent as email.
    All things good this query should return nothing.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s