Thanks!

From: [email protected] [mailto:[email protected]] On 
Behalf Of Rubens Almeida
Sent: Saturday, December 12, 2015 8:15 AM
To: Mazzaccaro, David <[email protected]>; 
[email protected]
Subject: RE: [Exchange] How to get notification of DAG failover?

I use this on all my clients running Exchange:
http://exchangeserverpro.com/test-exchangeserverhealth-ps1-v1-2-released/

Hope that helps.
Sent from Outlook Mail<http://go.microsoft.com/fwlink/?LinkId=550987> for 
Windows 10 phone


From: Mazzaccaro, David<mailto:[email protected]>
Sent: Friday, December 11, 2015 1:30 PM
To: [email protected]<mailto:[email protected]>
Subject: [Exchange] How to get notification of DAG failover?

Hi all,
What are others using for a reliable, immediate notification that an Exchange 
(2010) database has failed over to another server?
I found the below script, which looks perfect.  I am thinking of setting it as 
a scheduled task for every 30 min…
But I just wanted to check if anyone had any other/better/different methods.
Thx!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# MonitorDAG.ps1
# Script to monitor DAG in Exchange 2010
#
# Nuno Mota
# Team @MSExchangeGuru

Function sendEmail ([String] $body)
{
        $MailMessage = New-Object System.Net.Mail.MailMessage
        $MailMessage.From = 
"[email protected]<mailto:[email protected]>"
        
$MailMessage.To.Add("[email protected]<mailto:[email protected]>")
        $MailMessage.Subject = "DAG Not Healthy!"
        $MailMessage.Body = $body
        $MailMessage.Priority = "High"

        $SMTPClient = New-Object System.Net.Mail.SMTPClient
        $SMTPClient.Host = "HTCAS1.letsexchange.com"
        $SMTPClient.Send($MailMessage)
}



Function getExchangeServerADSite ([String] $excServer)
{
        # We could use WMI to check for the domain, but I think this method is 
better
        # Get-WmiObject Win32_NTDomain -ComputerName $excServer

        $configNC=([ADSI]"LDAP://RootDse").configurationNamingContext
        $search = new-object 
DirectoryServices.DirectorySearcher([ADSI]"LDAP://$configNC")
        $search.Filter = 
"(&(objectClass=msExchExchangeServer)(name=$excServer))"
        $search.PageSize = 1000
        [Void] $search.PropertiesToLoad.Add("msExchServerSite")

        Try {
               $adSite = [String] 
($search.FindOne()).Properties.Item("msExchServerSite")
               Return ($adSite.Split(",")[0]).Substring(3)
        } Catch {
               Return $null
        }
}



[Bool] $bolFailover = $False
[String] $errMessage = $null

Get-MailboxDatabase | Sort Name | ForEach {
        $db = $_.Name
        $curServer = $_.Server.Name
        $ownServer = $_.ActivationPreference | ? {$_.Value -eq 1}

        # Compare the server where the DB is currently active to the server 
where it should be
        If ($curServer -ne $ownServer.Key)
        {
               # Compare the AD sites of both servers
               $siteCur = getExchangeServerADSite $curServer
               $siteOwn = getExchangeServerADSite $ownServer.Key

               If ($siteCur -ne $null -and $siteOwn -ne $null -and $siteCur -ne 
$siteOwn)
               {
                       $errMessage += "`n$db on $curServer should be on 
$($ownServer.Key) (DIFFERENT AD SITE: $siteCur)!"
               }
               Else
               {
                       $errMessage += "`n$db on $curServer should be on 
$($ownServer.Key)!"
               }

               $bolFailover = $True
        }
}

$errMessage += "`n`n"

Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ForEach {
        If ($_.Status -notmatch "Mounted" -and $_.Status -notmatch "Healthy" 
-or $_.ContentIndexState -notmatch "Healthy")
        {
               $errMessage += "`n$($_.Name) - Status: $($_.Status) - Index: 
$($_.ContentIndexState)"
               $bolFailover = $True
        }
}

If ($bolFailover)
{
        sendEmail $errMessage
        #Schtasks.exe /Delete /TN "MonitorDAG" /F
}


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Reply via email to