07 November 2012

How to monitor Exchange 2010 database health

If you have fault tolerant RAID1 disk system, you can have a failure of one HDD. But when this happens, you are vulnerable. So you need a solution for monitoring this kind of events.

In Exchange 2010 you can have mirrored databases, where you expect the same kind of fault tolerance. If you don’t have a huge monitoring software, you can use a simple PowerShell script:

$date = Get-Date
"Adding Exchange snapin"
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
$mailboxservers = Get-ExchangeServer | ? {$_.serverrole -like "*mailbox*"}
$info = $mailboxservers | foreach {Get-MailboxDatabaseCopyStatus -Server $_.name}

$filename2 = "c:\serverinfo\Exchange Databases {0}.{1:d2}.{2:d2} {3:d2}.{4:d2}.csv" -f $date.year,$date.month,$date.day,$date.hour,$date.minute
$info | Export-Csv -Path $filename2 -encoding utf8
$info2 = $info | where {($_.Status -ne "Healthy" -and $_.Status -ne "Mounted") -or $_.ContentIndexState -ne "Healthy"}
$info3 = $info2 | ConvertTo-Html
$info4 = [string]$info3

if($info2){
Send-MailMessage -SmtpServer yoursmtpservername -To
to@addre.ss -From from@addre.ss -Subject "Exchange databases having bad times" -Body $info4 -BodyAsHtml
}

This script in short:

It finds all mailbox servers, on each of them gets the status of mailbox database copies and if anything is wrong with database or index status, then it sends a message. As a bonus it saves the full info to a CSV file for troubleshooting.

This script should be run with task scheduler every hour or so.

No comments:

Post a Comment