Remove Messages from Queue

Exchange.jpg

Overview:

There are times where messages become stuck in an Exchange Messaging Queue on a Transport Server.   This article describes on how to get the Queue Name and then how to remove those messages in that queue.

Example:

The first example is removing messages from the Poison Queue which can happen from time to time. In this case the name of the queue never changes and thus makes it easy. If you were to run Get-Queue -Server <EXCH TRANSPORT SERVER> it would return the Identity for the Poison Queue as <EXCH TRANSPORT SERVER>\Poison.  That being the case this is how you remove the messages:

Remove-Message -Server <EXCH TRANSPORT SERVER> -Filter {Queue -eq "<EXCH TRANSPORT SERVER>/Poison"} -WithNDR $false

IN the above example we are using the Remove-Message cmdlet and specifying the HUB Transport Server. If you have multiple stuck messages in a Highly Available configuration you would need to alter the <EXCH TRANSPORT SERVER> for each server in the array.

Something else to consider is your -Filter options  You are not limited to Queue, for instance you could choose Subject, and change the operator to -like)

Remove-Message -Server <EXCH TRANSPORT SERVER> -Filter {Subject -like "*Hello*"} -WithNDR $false

By doing this and adding the * you are grabbing any messages with "Hello" in the subject line

If you want to suppress the confirmation message just add -Confirm:$false to the end of the statement

The other command to know is:

Get-Queue -Server <EXCH TRANSPORT SERVER>

This cmdlet returns all the queues on a specific HUB TRANSPORT server.  This is important incase you have a bad queue in which you may want to manually delete e-mail messages.  You can run the same command above with the IDENTITY parameter from Get-Queue command.