Blog

Exchange Queue Length Check

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$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
 }

Posted in: Scripts, Technical

Leave a Comment (2) ↓

2 Comments

  1. Anthony January 21, 2013

    This script is perfect for what i need.

    No matter how i create the VB script, I always get the Invalid Character code 800A0408, line-1 char-1. Any ideas?

    reply
    • Anthony January 21, 2013

      I figured it out. I was using the VB extension and not power-shell. This script works perfectly.

      reply

Leave a Comment