Hi Muthu,
If I have understood your logic correctly it is as below.
1. Normal scenario all DBs will be Active on ActivationPreferance = 1
2. Schedule task with the script will be running say every hour, if it finds all normal no email triggered. If any DBs are Activated on any ActivationPreferance!=1 you get an email every hour, until you fix it(scripts variables are independent, will
not remember it has already notified this to you).
Now the question is, how about you tell us which part is not working, what is expected and what is the result you are getting.
Another way to go about is use eventvwr logs to determine if any failover has occured.
Applications and Services Logs\Microsoft\Exchange\HighAvailability\Operational. That log records database mount changes and various other stuff. There are a lot of event IDs that can pertain to Database copy changes. Event 205 is a database
mount.
You seemed to have refered this article.
Monitor DAG Database Failover
I would say why complicate this all simply use the existing cmtlet and use the output directly on email, you can review it directly without any logic to it. You would anyways want all these info to see what happened to the original DB etc.
#View Active mailbox database copies only
Get-MailboxDatabaseCopyStatus * -Active | Select Name,Status,MailboxServer,ActivationPreference,ContentIndexState | ft -AutoSize
Name Status MailboxServer ActivationPreference ContentIndexState
---- ------ ------------- -------------------- -----------------
DB2\EXCH-1 Mounted EXCH-1 1 Healthy
Test-DB\EXCH-2 Mounted EXCH-2 2 Healthy
#Use below to view all DBs
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | Select Name,Status,MailboxServer,ActivationPreference,ContentIndexState,Active | ft -AutoSize
Name Status MailboxServer ActivationPreference ContentIndexState Active
---- ------ ------------- -------------------- ----------------- ------
Test-DB\EXCH-1 Healthy EXCH-1 1 Healthy
Test-DB\EXCH-2 Mounted EXCH-2 2 Healthy
DB2\EXCH-1 Mounted EXCH-1 1 Healthy
References:
http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_27661317.html
List Active Mailbox Database Copies:
http://exchangeserverpro.com/powershell-tip-list-active-mailbox-database-copies-exchange-server-database-availability-group/
Displays Incorrect Activation Preference Value:
http://exchangeserverpro.com/get-mailboxdatabasecopystatus-displays-incorrect-activation-preference-value/