Powershell Scripts to Manage MSMQ

We can manage MSMQ using Powershell. Powershell scripts help you automate the management of MSMQ and provide a quick way to create queues, manage users and permissions, get queue information etc. We have seen several blogs on internet, but here we will try to provide a collective information related to MSMQ management.

In this blog we will discuss how to implement System.Messaging.MessageQueue to implement various MSMQ functionalities. We will cover following topics:

Adding user to the private queues and setting permissions Full Permission Restricted Permission

Deleting the Queues

I am uploading a powershell script which will implement all the mentioned functionalities. I will discuss the implementation of each of these functionalities today. To run any powershell script, please run the following command: set-executionpolicy unrestrictedIn order to create MSMQ, we need to implement the System.Messaging.MessageQueue.

Feed the input: Enter Queuename, Y/N – Private, Y/N – Transactional, Y/N – Journal (separate with comma)Get each value in a separate variable and then on the basis of whether the queue is private or not, form the Queue Path:

To delete the queue, we need to determine if the queue that we want to delete is a private or a public queue. The Queue deletion will depend on the queue path.On the basis of whether the queue is private or public, we will create the path accordingly and delete the queue.

[System.Messaging.MessageQueue]::Delete($qname)

You can use the following piece of code for deleting a private queue:$QueueName = Read-Host ‘Enter the queue name you want to delete’ $qname = “.\private$\” + $QueueName if ($msmq::Exists($qname)) { [System.Messaging.MessageQueue]::Delete($qname) }

For example:

Please note that in this script we have not used any code to handle the errors. In the upcoming blogs, we will discuss the implementation of managing messages in the MSMQ Queues. Also, if we are using Powershell Extensions or Windows Server 2012, then we can use Powershell commandlets to manage the MSMQ Queues. We will also discuss the use of these cmndlets in some time.

Thanks, this helped me work around a weird GUI bug. MSMQ was installed but didn't appear in Computer Management interface. I followed your guide to create queues with PowerShell. After that, MSMQ appeared!