Quantcast
Channel: Zohno Inc. » Exchange Monitoring
Viewing all articles
Browse latest Browse all 2

Exchange 2010 DAG Monitoring Script

$
0
0

This script is designed for large Exchange 2010 environments with a lot of mailbox databases. When you have more than Exchange mailbox database copies within a DAG (Database Availability Group), it’s hard to keep track of which copy is having replication issue. It’s very important to keep all the DAG database copies healthy since transaction logs won’t truncate until all the logs are played into all databases. Also note that when the database index is in a failed state, it’s not considered a healthy database. Powershell script below will monitor both database status and its index state. When the script detects a problem, it will simply send you an email alert with Excel report attached. This Excel CSV attachment is very useful when troubleshooting and it will pinpoint the failed databases. Enjoy and feel free to send us feedback (support at zohno dot com)

#Exchange 2010 DAG monitoring script
#######START CONFIG###########
$sendemailalertto="itadmin@yourdomain.com"
$YourSMTPServer="smtp.yourdomain.com"
#######END CONFIG###########
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Get-mailboxdatabase | Get-MailboxDatabaseCopyStatus | foreach {
if ($_.Status -ne "Healthy" -and $_.Status -ne "Mounted") {
$triggeralarmDB="yes"
}
}
#Monitor Exchange 2010 Database Copy Index State
Get-mailboxdatabase | Get-MailboxDatabaseCopyStatus | foreach {
if ($_.contentindexstate -ne "Healthy") {
$triggeralarmIndex="yes"
}
}
if ($triggeralarmDB -eq "yes") {
Get-mailboxdatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -ne "Healthy" -and $_.Status -ne "Mounted"} | select Name,DatabaseName,Status,MailboxServer,ActiveDatabaseCopy,ActivationSuspended | export-csv -Path c:\Zohno_DAG_Monitor.csv -NoTypeInformation
sleep 50
function send_email {
$EmailFrom = "Exchangeadmin@zohno.com"
$EmailTo = $sendemailalertto
$EmailSubject = "Exchange Replication Failed"
$SMTPServer = $YourSMTPServer
$emailbody = "Please see attached"
$emailattachment = "c:\Zohno_DAG_Monitor.csv"
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = ($emailfrom)
$mailmessage.To.add($emailto)
$mailmessage.Subject = $emailsubject
$mailmessage.Body = $emailbody
$attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')
$mailmessage.Attachments.Add($attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.Send($mailmessage)
}
send_email
}
if ($triggeralarmIndex -eq "yes") {
Get-mailboxdatabase | Get-MailboxDatabaseCopyStatus | where {$_.contentindexstate -ne "Healthy"} | select Name,DatabaseName,Status,ContentIndexState,MailboxServer,ActiveDatabaseCopy,ActivationSuspended | export-csv -Path c:\Bad_ContentIndexState_DBs.csv -NoTypeInformation
sleep 50
function send_email {
$EmailFrom = "Exchangeadmin@zohno.com"
$EmailTo = $sendemailalertto
$EmailSubject = "Exchange Replication Failed"
$SMTPServer = $YourSMTPServe
$emailbody = "Please take action. Database Content Index is not healthy `n
Run below cmdlet to repair the index database.`n
Update-MailboxDatabaseCopy $mailboxdatabase -CatalogOnly`n
`n
For more information, see:`n

http://technet.microsoft.com/en-us/library/dd335201.aspx

"
$emailattachment = "c:\Bad_ContentIndexState_DBs.csv"
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = ($emailfrom)
$mailmessage.To.add($emailto)
$mailmessage.Subject = $emailsubject
$mailmessage.Body = $emailbody
$attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')
$mailmessage.Attachments.Add($attachment)
$mailmessage.IsBodyHTML = $true
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.Send($mailmessage)
}
send_email
}


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images