Reputation: 8775
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 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.
Upvotes: 4
Views: 6421
Reputation: 667
Starting with Windows Server 2012 and Win8, PS has a Get-MsmqQueue command. It is faster than the get-wmiobject method in my tests.
Measure-Command {
$list = Get-MsmqQueue -QueueType Private | % {$_.QueueName}
}
Measure-Command {
$list = Get-WmiObject Win32_PerfRawdata_MSMQ_MSMQQueue | ?{$_.Name -match "private"} | %{$_.Name}
}
Upvotes: 2
Reputation: 4866
$obj = Get-WmiObject Win32_PerfRawdata_MSMQ_MSMQQueue ##will return an Object[] array
$obj[0].name ## will return the 1st Queue Name
Also, you can do this to find out more methods / properties on this object -
$obj | Get-Member
To List only private Qs, you may use this -
Get-WmiObject Win32_PerfRawdata_MSMQ_MSMQQueue |
?{$_.Name -match "private"} |
%{$_.Name}
Upvotes: 5