When developing in a semi-microservice system utilizing MSMQ as message queue, these queues get filled up by messages from other services from time to time.

To naively and semi-automatic handle these situations locally in my development environment I’m using some of following commands to clear the queues which I’m not currently interested in processing.

Warning: These commands is probably not a good idea to run in production. It goes without saying; if your queues in production are full, you should check for errors and fix the processing before clearing any message queues.

Clear queues by name

PS > Get-MsmqQueue -Name exactmatch | Clear-MsmqQueue
PS > Get-MsmqQueue -Name prefix* | Clear-MsmqQueue
PS > Get-MsmqQueue -Name *suffix | Clear-MsmqQueue

Clear queues by type

PS > Get-MsmqQueue -QueueType Private | Clear-MsmqQueue
PS > Get-MsmqQueue -QueueType SystemTransactionalDeadLetter | Clear-MsmqQueue