Share via


How to monitor Exchange Queues / How to setup an Alert for Exchange Queues...

#Author : Nishant Naidu

#Technet - i-TechNinja 

# https://social.technet.microsoft.com/profile/i-tech%20ninja/

#https://itechninja.blogspot.in/
#https://crazycerebro.blogspot.in

#load Snapin

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

#Set Mailing parameters

$sendMailMessageParams = @{

    Smtpserver = " smtp server "

    To         = " To? "

    From       = " From? "

}

 

# HTML Body 

$head = "<style>",

        "BODY { background-color: white; }",

        "TABLE { border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse; }",

        "TH { border-width: 1px; padding: 5px; border-style: solid; border-color: black; foreground-color: black; background-color: LightBlue}",

        "TD { border-width: 1px; padding: 5px; border-style: solid; border-color: black; foreground-color: black; background-color: white}",

        "</style>" | Out-String

 #Logic to setup

if ($Queue = Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true } | Get-Queue | Where-Object { $_.MessageCount -gt 200 } | Select Identity, DeliveryType, NextHopDomain, RiskLevel, MessageCount, Status, Velocity) {

    $body = $Queue | ConvertTo-Html -Head $head | Out-String

 

#Invoke     

Send-MailMessage -Subject "Exchange Queue Alerts-Threshold 200" -Priority High -Body $body -BodyAsHtml @sendMailMessageParams

}

else{

    Send-MailMessage -Subject "Exchange Queue Alerts-Threshold 200" -Body "Queues are below Threshold limit - 200 "-BodyAsHtml @sendMailMessageParams

}

How to Run?

1. Save this file as .ps1 wherever with whatever name you want to.

2. Open Task Scheduler

3. Create a New task and set the task occurrence for this .ps1 file.

Thanks You!