This script will validate the mailbox database status, content index status, copy queue length and replay queue length of the databases from the DAG. It will trigger an email notification to administrator if any of the below condition is true,
1. Database is not mounted on the preferred server
2. Database status is not mounted
3. Database status is not healthy
4. Copy queue length is more than the threshold value
5. Reply queue length is more than the threshold value
6. Content index state is not healthy
We can use this script to validate both Exchange 2010 and 2013 DAG.
We have to schedule a task to run this script. I suggest to schedule this to run every 30 mins and it will trigger an email ONLY when the condition is true. In this way we can avoid spamming administrator mailbox.
##########################################################################
# Check DAG Status and send email #
# #
# If you want to send the report as an email, please give $Mail = "True" #
##########################################################################
# Inputs for Email
$Subject = "DAG Status Report"
$FromAddress = "DAGStatusReport@testlab.com"
$ToAddress = "admin@testlab.com"
$Relay = "SMTP relay server FQDN"
$SMTPClient = New-Object System.Net.Mail.smtpClient
$MailMessage = New-Object System.Net.Mail.MailMessage
$Mail = "False"
# Threshold
$CQL = 50
$RQL = 100
#Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin
Set-ADServerSettings -ViewEntireForest $True
$body = $null
$body += '<style>'
$body += '<!-- '
$body += 'body { font: Calibri } '
$body += 'table { font: 11pt Calibri; border: 1px} '
$body += 'td { border: 1px ridge white; padding-left: 1px; padding-right: 1px } '
$body += 'p.header { font: 11pt Verdana; color: DarkBlue }'
$body += 'p.normal { font: 8pt Calibri; color: CadetBlue }'
$body += '-->'
$body += '</style>'
$body += '</head>'
$body += '<body>'
$body += "<p class=`"header`" align='center'><strong>DAG Status Report: " + $(get-date).toshortdatestring() + " @ " + $(get-date).ToshorttimeString() + " [IST]"
$ExchServerName = Get-MailboxServer | ?{$_.Databaseavailabilitygroup} | sort name | %{
$ExchServerName = $_.name
write-host "Processing" $_.name
$ccs = $null
$CCS = Get-MailboxDatabaseCopyStatus -Server $ExchServerName | Where { ($_.Status -ne "Mounted") -and ($_.Status -ne "Healthy") -or ($_.ContentIndexState -ne "Healthy") -or ($_.replayqueuelength -gt $RQL) -or ($_.CopyQueueLength -gt $CQL) -or (( $_.Status -eq "Mounted") -and ((get-mailboxdatabase $_.databasename).activationpreference[0].key.name -ne $_.activedatabasecopy )) }
if ($CCS -ne $null)
{
#Table Header
$body += '<table width=80% align=center>'
$body += '<td colspan=6 align=center style="background-color: #DCDCDC" border: 1 ; ><strong><font color= Black>' + ($exchservername).toupper() + '</font></strong></td></tr>'
$body += '<tr><td align="Center" style="background-color: #736F6E" width="13%" border: 1 Groove white;><p class="table" style="color: white"><b>Database</b></p></td>'
$body += '<td align="Center" style="background-color: #736F6E" width="10%" border: 1 Groove white;><p class="table" style="color: white"><b>ActiveServer</b></p></td>'
$body += '<td align="Center" style="background-color: #736F6E" width="12%" border: 1 Groove white;><p class="table" style="color: white"><b>Status</b></p></td>'
$body += '<td align="Center" style="background-color: #736F6E" width="7%" border: 1 Groove white;><p class="table" style="color: white"><b>Copy QL</b></p></td>'
$body += '<td align="Center" style="background-color: #736F6E" width="8%" border: 1 Groove white;><p class="table" style="color: white"><b>Replay QL</b></p></td>'
$body += '<td align="Center" style="background-color: #736F6E" width="10%" border: 1 Groove white;><p class="table" style="color: white"><b>Content Index </b></p></td></tr>'
$ccs | foreach {
$body += '<tr><td align="Center" border: 1 Groove white;>' + $_.Databasename + "</td>"
$body += '<td align="Center" border: 1 Groove white; bgcolor=#FEEC80 >' + $_.activedatabasecopy.toupper() + "</td>"
if (($_.Status -eq "Healthy") -or ($_.Status -eq "Mounted"))
{
$body += '<td align="Center" border: 1 Groove white;>' + $_.Status + "</td>"}
Else
{
$body += '<td align="Center" border: 1 Groove white; bgcolor=#FEEC80 >' + $_.Status + "</td>"
}
if ($_.CopyQueueLength -ge $CQL)
{
$body += '<td align="Center" border: 1 Groove white; bgcolor=#FEEC80>' + $_.CopyQueueLength + "</td>"
}
Else
{
$body += '<td align="Center" border: 1 Groove white;>' + $_.CopyQueueLength + "</td>"
}
if ($_.ReplayQueueLength -ge $RQL)
{
$body += '<td align="Center" border: 1 Groove white; bgcolor=#FEEC80>' + $_.ReplayQueueLength + "</td>"
}
Else
{
$body += '<td align="Center" border: 1 Groove white;>' + $_.ReplayQueueLength + "</td>"
}
if ($_.ContentIndexState -eq "Healthy")
{
$body += '<td align="Center" border: 1 Groove white;>' + $_.ContentIndexState + "</td></tr>"
}
Else
{
$body += '<td align="Center" border: 1 Groove white; bgcolor=#FEEC80 >' + $_.ContentIndexState + "</td></tr>"
}
}
$body += '</table><br>'
}
}
if ($Mail -eq "True")
{
$body += "Report Completed"
##############################################################################
$MailMessage.Subject = "$Subject"
$MailMessage.Body = $body
$MailMessage.sender = "$FromAddress"
$MailMessage.From = "$FromAddress"
$MailMessage.To.add("$ToAddress")
#$MailMessage.CC.add("$CCAddress")
#$MailMessage.CC.add("$CCAddress2")
$MailMessage.Priority = [System.Net.Mail.MailPriority]::High
$MailMessage.IsBodyHTML = $True
$smtpclient.host = "$Relay"
$smtpclient.send($MailMessage)
#############################################################################
}
else
{
$Date = get-date
$FileName = 'DAG_Status_Report'
$FileName += $Date.year.tostring()
$FileName += $Date.month.tostring()
$FileName += $Date.day.tostring()
$FileName += '.html'
$body += "Report Completed"
set-content $FileName -value $body
}
#######################End of the Script##############################
Sample HTML Output