Click here to Skip to main content
15,615,466 members
Articles / Programming Languages / PowerShell
Posted 28 Oct 2014

Tagged as


6 bookmarked

PowerShell: Create MSMQ

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
28 Oct 2014CPOL
PowerShell: Create MSMQ

AT work, I use MSMQ a fair bit, and I also use NServiceBus a fair bit of late, which thankfully takes care of creating all the queues needed. But, for those times when you really need to make a bunch of queues, it can be a time consuming exercise, so I decided to see if my new found PowerShell skills could automate this process (remember I am still learning, so this may not be the best/most current way, in fact I know for Windows 8.1/Windows Server, there is a later more groovy API. But for now, this is what I came up with:

function printUsage() 
    Write-Host "Usage is CreateQueue.ps1 -queueName SomeQueuName 
        -isTransactional $true -isJournalEnabled $true 
        -userName mclocal\barbers -isAdminUser $true"
try {
    $fullQueueName = ".\private$\" + $queueName
    If ([System.Messaging.MessageQueue]::Exists($fullQueueName))
        Write-Host($fullQueueName + " queue already exists")
        $newQ = [System.Messaging.MessageQueue]::Create($fullQueueName, 
        if ($isJournalEnabled)
            $newQ.UseJournalQueue = $True
        if ($isAdminUser)
            Write-Host("NOT ADMIN")
catch [Exception] {
   Write-Host $_.Exception.ToString()

This will allow you to create a private queue of your choice of name, where you can also pick the following:

  • Whether it is a transactional queue
  • If journaling is enabled
  • If it is an admin user queue

Hope it helps!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.


I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions

Questiondoes this work only same server Pin
Amit Patel198511-Mar-20 3:24
Amit Patel198511-Mar-20 3:24 
GeneralMy vote of 5 Pin
Phebous30-Oct-14 16:57
Phebous30-Oct-14 16:57 
GeneralRe: My vote of 5 Pin
Sacha Barber30-Oct-14 20:43
Sacha Barber30-Oct-14 20:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.