June 22, 2018

PowerShell :: check the Exchange 2010 queues for Nagios

PowerShell ISE logo
(Last Updated On: 17th September 2016)

I wrote this little script to monitor the Exchange 2010 mail queues and flag up when there is some mail stuck in there.  In most infrastructures your emails will probably move onward to either a relay or AV appliance and a failure of one of these will see mail begin to back up on your Exchange server.  The failure of key services or low disk space can also cause mail transport to lock up and without this little script you may find your users find out before you do!

As an added bonus this script will also error when the Exchange Transport service has stopped.

There are no changes needed for this to work and you can follow this guide to get it working with NsClient.

I’ve also got a similar script here for Postfix.

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.e2010

try 
{
$a = get-queue | Get-Message | Where-object {$_.DateReceived -lt (get-date).AddMinutes(-10)}
}
catch
{
exit 2
}
if (!$a)
{
echo " No mail in the queue older than 10 minutes"
exit 0
}
else
{
echo "Mail has been held in the queue for over 10 minutes!"
exit 2
}

Previous «
Next »

Simon is a sysadmin for Local Government in North Yorkshire with a real passion for security and coding.

Leave a Reply

Subscribe to SYNACK via Email

%d bloggers like this: