Automated MSMQ Setup with Powershell

Question:

I am in the process of configuring a new test server for an application I support. It uses around 35 different MSMQ queues and creating these manually is obviously not loads of fun. Especially since the production version of the application is also moving servers so I’ll get to do this all over again. What I’m looking for is an automated way to create these queues and Powershell (based on my limited knowledge of it) seems like the way to go.

Does anyone have any tips on how I might go about accomplishing this?

Answer:

I think the approach you should take is to create your own Powershell cmdlet (Commandlet). Basically, you inherit from a base class, override a method, and that’s the method that gets called when you call that cmdlet from Powershell. This way you can do what you need to do in C# and just call it from Powershell. Figure something like this:

EDIT: Forgot to link to MSDN for creating cmdlets: http://msdn.microsoft.com/en-us/library/dd878294(VS.85).aspx

You would then call this cmdlet from Powershell something like this:

Then, to use MSMQ, there are many samples online on how to accomplish this from within C#:

Here’s just one of them….

Source:

Automated MSMQ Setup with Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply