Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications


Clearing Your Message Queue

Post Author: Joe D365 |

Microsoft Message Queuing (MSMQ) is a handy feature that can be used for system integrations. In a perfect world, your queue would always stay clean. However, some integrations have a tendency to leave messages lingering around. Fortunately, clearing messages is quick and easy, and in today's blog, we will go through the steps you need to keep your message queue spic and span!

In order to manually clear Message Queueing in Windows Computer Management, follow these steps:

1. First, go to Services and Applications > Message Queuing.

2. Right-click on the queue you want to clear, and then select All Tasks > Purge.

Note: If you are unsure about deleting the messages, or you have data hoarding issues, you can export the list first.

Message Queue

Purging the queue can be automated using PowerShell. Let's say you have messages labeled as String Message and Variables Message in a Private Queue named PowerObjects.

Message Queue

You will want to clear all of the messages using the following script:

$mq = new-object -TypeName System.Messaging.MessageQueue ".private$PowerObjects"

    $mq.Purge()

The first line instantiates the queue you want to clean. The second line clears the entire queue.

Now you may ask, what if I don't want to clear the entire queue? In that case, simply use PowerShell to clear just the Variables Messages using the following script:

$mq = new-object -TypeName System.Messaging.MessageQueue ".private$PowerObjects"

$mq | ? {$_.Label -eq "Variables Message"} | % { $mq.ReceiveById($_.Id) }

The first line instantiates the queue you want to clean. The second line filters the queue by Label and loops through those messages to receive them, which removes them from the queue. If you want to verify what will be removed first, or see some of the other message properties to filter on, run the first half of the script: $mq | ? {$_.Label -eq "Variables Message"}.

If you have chronic queue issues, PowerShell can be saved in a .ps1 then scheduled using Task Scheduler to help control the size of dead messages in your queues.

That's all for the blog today! Did you know that our monthly newsletter features tips and trick each month just like this one? Subscribe today to get updates delivered directly to your inbox!

Happy CRM'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

PowerObjects Recommends