Exchange Queue Length Check

Heres a script to check the queue length in exchange.
Just modify the $Threshold from 10 to whatever you desire.

$snapinversion = 0;
 foreach ( $snap in get-pssnapin -registered)
 {
     if ( $snap.Name -eq 'Microsoft.Exchange.Management.Powershell.Admin' )
     {
         $snapinversion = 2007;
         Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -ErrorAction SilentlyContinue
  
     }
     if ( $snap.Name -eq 'Microsoft.Exchange.Management.Powershell.Support' )
     {
         $snapinversion = 2010;
         Add-PSSnapin Microsoft.Exchange.Management.Powershell.Setup -ErrorAction SilentlyContinue
         Add-PSSnapin Microsoft.Exchange.Management.Powershell.Support -ErrorAction SilentlyContinue
         Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010 -ErrorAction SilentlyContinue
     }
 }
  
 if($snapinversion -eq 0)
 {
     Write-Host "Exchange Powershell Snapin missing";
     Exit 1003;
 }
 $Threshold = 10
 $MessageCount = Get-ExchangeServer | Where { $_.isHubTransportServer -eq $true } | get-queue |  foreach -begin {$total=0} -process {$total+=$_.messageCount} -end {$total}
 if ($MessageCount -gt $Threshold)
 {
 Write-Host "Warning: $MessageCount Emails in Queue.";
 Exit 1010
 } Else {
 Write-Host "$MessageCount/$Threshold Emails in Queue.";
 Exit 0
 }

2 Comments

Leave a Reply

Your email address will not be published.