none
Exchange Queue Viewer has different results than PowerShell Get-Queue -Filter { MessageCount -ge $Threshold } RRS feed

  • Question

  • We have our Exchange Server 2010 SP3 sending email through our Barracuda, and the Barracuda has some Rate Control policies set up because we have staff sending out bulk emails.  I put in place a powershell script to alert us when the Message Queues reached a certain threshold. The powershell script runs every 5 minutes from the Task Scheduler, and it currently writes to the event log and sends an email if the Queue Message count is over a certain threshold. However, we are also manually watching the Exchange Queue Viewer, and we are seeing dramatically different message counts, between the Queue Viewer and PowerShell Get-Queue cmdlet. The Queue Viewer refreshing is showing a Message Count well over 80, where the Get-Queue is showing a Message Count less than 30.

    Below is the script that is being run directly on the Exchange Server (Hub and Transport), I removed the domain name and email address. 

    I am looking for what might be causing the dramatic differences in the Message Count between the Queue Viewer and the Get-Queue cmdlet, so that I can adjust my script to more accurately report and alert when we near high Message Count threshold.

    I understand that Get-Queue only being run every 5 minutes is just a point in time, but even if I refresh the Queue Viewer at the time the Task Manager runs the powershell script, this is only at times where the MessageQueue is near the 30 message threshold. I am getting vastly different Message Counts, the Queue Viewer is showing above 80, and the Get-Queue MessageCount written to the event log and emailed is showing at the time a MessageCount under 30.

    Any assistance is appreciated,

    Thanks,

    $serverName = get-content env:computername
    $FromEmail = "$($serverName)@ CHANGED TO MY DOMAIN"
    [string[]]$ToBCCEmail = "MY EMAIL AT MY DOMAIN"
    [string[]]$ToEmail = " DISTRIBUTION GROUP AT MY DOMAIN"
    $smtpServer = "localhost"
    $AlertThreshold = [int]30
    
    Write-Host "Starting Message Queue Monitor`n"
    function Load_Exchange_Tools {
    	if (-not (Get-pssnapin | ? {$_.name -like 'Microsoft.Exchange.Management.PowerShell.e2010'})) {
    		Add-PSSnapin Microsoft.Exchange.Management.PowerShell.e2010
    	}
    }
    Write-Host "Loading Exchange Tools`n"
    Load_Exchange_Tools
    Write-Host "Loaded Exchange Tools`n"
    
    Write-Host "Checking Message Queues`n"
    Get-Queue -Filter { MessageCount -ge 0 } | ForEach-Object {$EventLogMessage += "Next Hop Domain: $($_.NextHopDomain) `t`tDelivery Type: $($_.DeliveryType) `t`tStatus: $($_.Status) `t`tMessage Count: $($_.MessageCount) `t`tNext Retry Time: $($_.NextRetryTime) `t`tLast Error: $($_.LastError) `t`tIdentity: $($_.Identity)`n`n"}
    Write-EventLog -LogName Application -Source "Exchange Queue Monitor" -EntryType Information -EventId 1 -Message $EventLogMessage
    Write-Host $EventLogMessage
    
    $check = @(Get-Queue -Filter { MessageCount -ge $AlertThreshold }).Count
    
    Write-Host "$check`n"
    Write-Host $check
    
    Write-Host "Checked Message Queues`n"
    
    if($check -gt 0)
    {
    	Write-Host "Sending Message Queue Notification`n"
    	Write-EventLog -LogName Application -Source "Exchange Queue Monitor" -EntryType Information -EventId 1 -Message "Sending Message Queue Notification`n"
    	$DateStr = (Get-Date).ToString('MM-dd-yyyy hh:mm')
    	$messageSubject = "AUTOMATED URGENT NOTIFICATION: Email Message Queue Status Alert $($DateStr)"
    	$messageBody = "The following queue(s) are at or above queue threshold of $($AlertThreshold) `n`n"
    	$messageBody += "Mitigation may be required!!!`n`n"
    	Get-Queue -Filter { MessageCount -ge $AlertThreshold } | ForEach-Object {$messageBody += "Next Hop Domain: $($_.NextHopDomain) `t`tDelivery Type: $($_.DeliveryType) `t`tStatus: $($_.Status) `t`tMessage Count: $($_.MessageCount) `t`tNext Retry Time: $($_.NextRetryTime) `t`tLast Error: $($_.LastError) `t`tIdentity: $($_.Identity)`n`n"}
    	Write-Host $messageBody
    
    	send-mailMessage -to $ToEmail -Bcc $ToBCCEmail -subject $messageSubject -from $FromEmail -body $messageBody -Priority High -SmtpServer $smtpServer
    	Write-Host "Sent Message Queue Notification`n"
    	Write-EventLog -LogName Application -Source "Exchange Queue Monitor" -EntryType Information -EventId 1 -Message "Sent Message Queue Notification`n"
    }
    Write-Host "Completed Message Queue Monitor`n"
    


    Wednesday, January 29, 2014 2:47 PM

All replies

  • unless you can guarantee your refresh is at the exact millisecond the script runs you may get different results in a busy org with a high volume. you are better to use statistics collected over time e.g. through perfmon.
    Thursday, January 30, 2014 10:28 PM