He's the code I wrote for vCheck-Exchange which tests that: https://github.com/philrandal/vCheck-Exchange/blob/master/Plugins/16%20Exchange%202010%20Active%20DB%20not%20on%20Preferred%20Server%20.ps1
Should be easy to adapt. Cheers, Phil -- Phil Randal Infrastructure Engineer Hoople Ltd | Thorn Office Centre | Hereford | HR2 6JT Tel : 01432 260415 |Email: [email protected]<mailto:[email protected]> General email: [email protected]<mailto:[email protected]> Website: www.hoopleltd.co.uk<http://www.hoopleltd.co.uk/> From: [email protected] [mailto:[email protected]] On Behalf Of Mazzaccaro, David Sent: 11 December 2015 15:44 To: [email protected] Subject: [Exchange] RE: How to get notification of DAG failover? I just noticed that this script will notify in the event of DAG failover, but is there a way to notify me every 30 mins that all DBs are indeed running on their correct (activation preference 1) servers? This is more of what I am looking for. From: [email protected]<mailto:[email protected]> [mailto:[email protected]] On Behalf Of Mazzaccaro, David Sent: Friday, December 11, 2015 10:29 AM 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 } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hoople Ltd, Registered in England and Wales No. 7556595 Registered office: Plough Lane, Hereford, HR4 0LE "Any opinion expressed in this e-mail or any attached files are those of the individual and not necessarily those of Hoople Ltd. You should be aware that Hoople Ltd. monitors its email service. This e-mail and any attached files are confidential and intended solely for the use of the addressee. This communication may contain material protected by law from being passed on. If you are not the intended recipient and have received this e-mail in error, you are advised that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. If you have received this e-mail in error please contact the sender immediately and destroy all copies of it."
