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?

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