Friday, 13 November 2009

Delete all MSMQ queues at some PC with PowerShell

We have a small issue at one of our production servers. Once something generated ~10K queues with Guid-like names. Since then they were not deleted as there was a problem: standard MSMQ manager doesn't allow deleting several queues at once.

What to do? Powershell, of course! :) Here goes the script:


[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("someserver") | % {".\" + $_.QueueName} | % {[System.Messaging.MessageQueue]::Delete($_); }

You may also filter them by name if you do not need to remove them all as I need:

[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("someserver") | % {".\" + $_.QueueName} | ? {$_ -match "SOME_REGEX_FILTER"} | % {[System.Messaging.MessageQueue]::Delete($_); }

And SOME_REGEX_FILTER is... Yeap, some regex filter :) The -match operator allow us using regular expressions in the Where-Object (alias "?") clause.

Have fun with PowerShell!


Anonymous said...

How do you run this?

Kiquenet said...

How can I purgue queues in remote server?

Unknown said...

Thanks to the writer of this article. I appreciate your effort in making this informational blogs. I know it's not easy to do this but you have done a really great job. Congrats. I'm pretty sure your readers enjoying it a lots.


Unknown said...

Thanks for sharing such a wonderful article, I hope you could inspire more people. Visit my site too.

Unknown said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.

eddyshaw9272711 said...

I discovered your blog site on google and test a number of of your early posts. Proceed to maintain up the excellent operate. I simply extra up your RSS feed to my MSN News Reader. In search of ahead to studying extra from you afterward!… best online casinos