Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I retrieve the names of all of the private MSMQ queues on the local machine, without using System.Messaging.MessageQueue.GetPrivateQueuesByMachine(".")? I'm using PowerShell so any solution using COM, WMI, or .NET is acceptable, although the latter is preferable.

Note that this StackOverflow question has a solution that returns all of the queue objects. I don't want the objects (it's too slow and a little flakey when there are lots of queues), I just want their names.

share|improve this question

At this omputer I have no MSMQ installed, but this should it do.

 gwmi -class Win32_PerfRawData_MSMQ_MSMQQueue | Select Name

I use this to get the number of messages in the queue of remote servers.

$dataRaw = Invoke-Command -Session $sessions -ScriptBlock { gwmi -class Win32_PerfRawData_MSMQ_MSMQQueue } 
$data | Sort-Object -Property PSComputerName,Name  | 
Format-Table  DisplayName, MessagesInQueue, PSComputerName
share|improve this answer

There is a generic cmdlet command available in powershell Get-MsmqQueue, to accomplish the task in powershell: Get-MsmqQueue –QueueType Private | select QueueName

This will return names of the private queues in string array. Please be aware the type returned by get-msmqqueue cmdlet is Microsoft.Msmq.PowerShell.Commands.MessageQueue, not System.Messaging.MessageQueue, and seems these two types cannot be converted to each other.

share|improve this answer
Can you provide any other details about these commands? – GregL Apr 18 at 15:07
updated with more details, any specific area you looking for? – Kai Zhao Apr 18 at 15:24
Nothing in particular, just not a single line of code, without any context or explanation. – GregL Apr 18 at 15:27

In Powershell everything is an object. You can choose to list certain properties by using the select command which effectively discards the objects.

share|improve this answer
Thanks, @uSlackr. I'm trying to avoid instantiating all the objects if I can help it, because it's very slow. Ideally, I want to instantiate only those queues that have a name matching a certain pattern. Since there is no API for that (that I'm aware of) I want to get the list of names, filter that, then retrieve each queue individually. – Damian Powell Jun 15 '12 at 14:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.