Sunday, November 27, 2016

Powershell Scripting: check Exchange mail queues...

This is a guest post my Mr. Troy Collins

This script checks the Mail Queues and if they are too big it will auto e-mail.

When mail queues get big mail flow may stop working.. ​ This script can be very helpful and should be added to Schedule task to run every 15 minutes.

This script will test Exchange mail queues and e-mail if amount of message are too many.
Writen by Troy Collin

$server = hostname

#$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$server/powershell/  -Authentication Kerberos
#Import-PSSession $Session
add-pssnapin Microsoft.Exchange.Management.PowerShell.SnapIn
Write-host "Exchange Snapin now eanbled."

$total_messages = get-transportserver| get-queue |  foreach -begin {$total=0} -process {$total+=$_.messageCount} -end {$total}
if ($total_messages -gt 200)
write-host "messages are high"
$message = "`n*******Automated E-mail DO NOT REPLY******`n
Exchange Message Queues test. `n

`n`nAlert Check message queue!!
current total is $total_messages`n `n
Thank you" 

$emailFrom = "Mail Queue problem! <>"
$smtpServer = "SMTPServer"
#$emailTo = ""
$emailSubject    = "Mail Queue Status script"
$file = "$Filename"

######### End of Send email variables ###############

$mailMessageParameters = @{
From       = $emailFrom
To         = $emailTo
Subject    = $emailSubject
SmtpServer = $smtpServer
Body       = $message
# Attachment = $REPORT


Send-MailMessage @mailMessageParameters

} else {
Write-host "messages are not high"


  1. Am I the only person, who has problems with this script? It doesn't work at all. I would be very grateful, if someone helped me.

    1. I will reach out to the creator and ask him if he can revisit it.
      Thanks for bringing this to my attention.

    2. Greetings, there might be a problem with what version of MS exchange the script is running against. I just ran it on a lab system Exchange 2013 and it does work. however it seems it will not work after exchange 2013.

      Exchange Snapin now eanbled.
      Creating a new session for implicit remoting of "Get-TransportServer" command...
      WARNING: The Get-TransportServer cmdlet will be removed in a future version of Exchange. Use the Get-TransportService
      cmdlet instead. If you have any scripts that use the Get-TransportServer cmdlet, update them to use the
      Get-TransportService cmdlet. For more information, see
      messages are not high

  2. This comment has been removed by the author.