EXCHANGE 2010 Dag Failover

Hi All,

I am looking for a script where if the db has been failed over to passive node we should get an alert on it.

$logfile = $logdir + "DBStatus.log"
$log = ""
$DAG=Get-MailboxDatabase |Where-Object {$_.ReplicationType -Like "Remote" -and $_.MasterServerOrAvailabilityGroup -Like "$DAG"} |Sort-Object Name
foreach ( $i in $DAG)
{
$DB=$i.Name
$xNow=$i.Server.Name
$dbown=$i.ActivationPreference| Where {$_.Value -eq 1}
#Write-output "DB Name-" $DB
#Write-output "DB Mounted on server"$xnow
#Write-output $dbown
If ($xNow -ne $dbOwn.Key)
 {
   $log += $DB+" Mounted in Passive copy "+$xNow+";"+$DB+" should be mounted on "+$DBown.Key
       $count=$count+1
       $log+= "`n"
 }
}
If ($count -ne 0)
{
$Test="Databases running on Passive Node servers"
$log += $Count,$Test
}
else 
{
$log += "All the databases running on correctly !!!"
}
logToFile $logfile $log
Send-MailMessage -To $emailTo -From $emailfrom -SmtpServer $smtpServer -Body $log -Subject "$DAG DAG Mount Status $date"

But it is not working as expeted can you please review on it

Regards

June 8th, 2015 5:29am

So, I always wonder why the need for this? DAG members should be considered peers, not Active/Passive.

If you want to prevent automatic failover to another server, that is can be done quite easily.

Free Windows Admin Tool Kit Click here and download it now
June 8th, 2015 9:20am

Thank sandy for tge update my objective is whenever db has been failed over to passive copy or second copy we should get notified or scheluded task to monitor on it Regards Muthu
June 8th, 2015 2:12pm

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/

Free Windows Admin Tool Kit Click here and download it now
June 8th, 2015 11:40pm

Hi Muthu,

I have reviewed your script and found this issue, due to which its not giving any meaningful results as such even when it runs without errors.

Incorrect:

$DAG=Get-MailboxDatabase |Where-Object {$_.ReplicationType -Like "Remote" -and $_.MasterServerOrAvailabilityGroup -Like "$DAG"} |Sort-Object Name

Corrected:

$DAG=Get-MailboxDatabase |Where-Object {$_.ReplicationType -Like "Remote" -and $_.MasterServerOrAvailabilityGroup -Like "*"} |Sort-Object Name

The $DAG object which you are using to store the Database information is again being called inside "$_.MasterServerOrAvailabilityGroup -Like "$DAG"}" ,which ofcourse would be a typo or something else.

Either it has to be a valid DAGname or

$DAGname variable should be different with the DAGname assigned earlier on the script

or just as I have used "*" all DAGs will be listed.

Basically before you run the script make sure you are able to get the desired output by running this:

[PS] C:\Scripts>Get-MailboxDatabase |Where-Object{$_.ReplicationType -Like "Remote" -and $_.MasterServerOrAvailabilityGroup -Like "*"} |Sort-Object Name

Name                           Server          Recovery        ReplicationType
----                           ------          --------        ---------------
Test-DB                        EXCH-2      False           Remote


NOTE:- That you might want to correct.

Even if Write-Output is doing what you want, you should be using Write-Host which actually is meant for console output.

Which should I use: write-host, write-output
http://stackoverflow.com/questions/8755497/which-should-i-use-write-host-write-output-or-consolewriteline

Write-Output
https://technet.microsoft.com/en-us/library/hh849921.aspx

June 9th, 2015 12:01am

Thanks satya jot ofr the update . however it gives only the mounted or health. It doesnt shows where the pefence number or as it should be .

And i will review my script as updated by you.

Regards

Muthu

Free Windows Admin Tool Kit Click here and download it now
June 9th, 2015 11:15am

Hi ,

Can i have similar scripts  for HT monitoring queues. f the queue goes beyond 25  we should get an email

Regards

Muthu

June 17th, 2015 4:20pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics