Today I was fixing a troubled installation of an inherited ETL framework.
Two required message queues were missing from the environment. In fact, MSMQ was not even installed on the server.
I installed MSMQ, but “Message Queuing” was still missing from the “Computer Management” interface. How was I gonna create the queues now?
You guessed it: PowerShell.
[Reflection.Assembly]::LoadWithPartialName('System.Messaging') $msmq = [System.Messaging.MessageQueue] $msmq::Create('.private$etl_notifications', $true) $msmq::Create('.private$etl_transform_tasks', $true)
Line 1 loads the System.Messaging assembly, the .NET interface to MSMQ.
Line 2 makes the next lines easier to read. The MessageQueue class has static methods to manage queue lifecycle. Now we can refer to it as just
Lines 3 and 4 call MessageQueue.Create to do the actual work of creating the queues
The framework uses private queues, so the queue names are prefixed with
$true means it’s a transactional queue.
The weird thing is that “Message Queuing” appeared in the “Computer Management” interface after I added the queues.
Had that happened in the first place, I would never have figured out the PowerShell way! So, thanks, buggy GUI, I guess.
Even more thanks to Jainath V R for his step-by-step PowerShell guide!