Exchange 2010 PowerShell Script to alert when Replay Queue Length gets above a Threshold

2017-12-07T09:45:43+00:00 March 5th, 2012|Exchange, PowerShell|

Just a quick PowerShell script we’ve wrote that will basically alert you when a Replay Queue Length goes above a configured threshold (In the below Scripts Case it’s a 1000 but you can alter to what you want)

It’s best to configure the below PowerShell to run in task scheduler on your server on an hourly occurrence . Please note an email will only be triggered when the Queue length goes above the value you’ve specified.

Please Edit the Below highlighted in red to suit your needs and then save the script to a PS1 and your all ready to run it Smile

 

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Function sendEmail ([String] $body)
{
    $MailMessage = New-Object System.Net.Mail.MailMessage
    $MailMessage.From = EmailAddressFrom@Email.com
    $MailMessage.To.Add(EmailAddressTo@Email.com)
    $MailMessage.Subject = "Replay Queue Length Above 1000"
    $MailMessage.Body = $body
    $MailMessage.Priority = "High"

    $SMTPClient = New-Object System.Net.Mail.SMTPClient
    $SMTPClient.Host = "ExchangeServerName"
    $SMTPClient.Send($MailMessage)
}

Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ForEach {
    If ($_.ReplayQueueLength -gt "1000")
    {
$body += "ServerName"
$body += "`r`n "
$body += $_.MailboxServer
$body += "`r`n "
$body += "Database"
$body += "`r`n "
$body += $_.DatabaseName
$body += "`r`n "
$body += "Replay Queue Length"
$body += "`r`n "
$body += $_.ReplayQueueLength
$body += "`r`n "
$body += "`r`n "
$body += "`r`n "
$body += "`r`n "
}
}
 
if ($Body -ne $null)
{
sendemail $Body}"

 

The Outpoint to email  will be like below

ServerName

TempServer

Database

TempDB

Replay Queue Length

9482