A simple PowerShell script that can run on an Exchange 2010 server. This script will send an email report of the Mailbox Database Copy Status for each of your Exchange 2010 servers with the Mailbox Role.
Step 01: Define some variables
- $MessageBodyServerHeadingXX – Heading that separates the statistics from each server.
$SMTPServer = "hubtransport.domain.com" $FromAddr = "GroupName@domain.com" $ToAddr = "GroupName@domain.com" $Subject = "Exchange Mailbox Database Copy Status" $MessageBody = "" $MessageBodyServerHeading01 = "<ServerName> DATABASE COPY STATUS" $MessageBodyServerHeading02 = "<ServerName> DATABASE COPY STATUS"
Step 02: Get the statistics from each server and store them in a variable
$<FirstServerName>Status = Get-MailboxDatabaseCopyStatus -server <FirstServerName> | ft @{label="Database Name";width=40;expression={$_.Name}}, @{label="DB Status";width=10;expression={$_.Status}}, @{label="Copy Queue";width=5;expression={$_.CopyQueueLength}}, @{label="Replay Queue";width=6;expression={$_.ReplayQueueLength}}, @{label="Index State";width=11;expression={$_.ContentIndexState}} | out-string $<SecondServerName>Status = Get-MailboxDatabaseCopyStatus -server <SecondServerName> | ft @{label="Database Name";width=40;expression={$_.Name}}, @{label="DB Status";width=10;expression={$_.Status}}, @{label="Copy Queue";width=5;expression={$_.CopyQueueLength}}, @{label="Replay Queue";width=6;expression={$_.ReplayQueueLength}}, @{label="Index State";width=11;expression={$_.ContentIndexState}} | out-string
Step 03: Combine the variables into the message body
$MessageBody = $MessageBodyServerHeading01 + $<FirstServerName>Status + $MessageBodyServerHeading02 + $<SecondServerName>Status
Step 04: Send the Email
Send-MailMessage -from $FromAddr -to $ToAddr -subject $Subject -body $MessageBody -smtpServer $SMTPServer