MSMQ Cmdlets not working as expected

Hi,

So I’m working with the Set-MsmqQueueAcl cmdlet and it doesn’t work as advertised.
First issue: the documentation on TechNet (located at https://technet.microsoft.com/en-us/library/hh405014(v=vs.85).aspx) doesn’t work in practice. The acceptable values for Allow are different than those listed on TechNet, and a comma-separated list doesn’t appear to work.

Second issue: The DeleteMessage Allow setting doesn’t change the permissions that are displayed in the UI, though it looks like it changes them as far as PowerShell is concerned.

Is there a reliable source of info on the MSMQ cmdlets out there?

Thanks,
Joel

I determined that the ‘Delete’ that shows in the UI is for deleting the queue. I don’t believe that the ‘Delete Message’ permission shows in the UI.
I now trust my PowerShell results over the UI.

As a quick note - see https://powershell.org/forum-etiquette/; you don’t want to reply to your own post, because it kind of “hides” you from the list of unanswered questions. A lot of us use that to find posts needing answering. Glad I checked this one :).

I’m not finding a lot of info on the MSMQ cmdlets, unfortunately, which makes me suspect nobody’s created much. I’m trying to see if there’s someplace they accept feedback on their docs, and I’ll let you know if I do. Meantime, if you’re in Connect, I think the Visual Studio project is where people have been logging MSMQ bugs, so a doc bug wouldn’t be out of place.

You can also open a ticket with product support. I know, nobody ever does that, but it does flag the problem in a way nothing else quite matches.

I did some work with MSMQ and Powershell a while back. I found that there wasn’t much resource out there. I ended up working with one of our developers and created two scripts, one that will create a new MSMQ, and one that will purge all messages in an MSMQ. I used the .NET framework MessageQueue class, see this page for full details
https://msdn.microsoft.com/en-us/library/system.messaging.messagequeue(v=vs.110).aspx

The New-MSMQueue script will create one or more queues using the -QueueName parameter, eg

.\New-MSMQueue.ps1 -QueueName ".\Private$\Queue1",".\Private$\Queue2"

The final line of this script gives the Everyone group to FullControl on the queue - it sounds like you are trying to set an ACL so maybe this will help

Maybe you can pick something out of my scripts that will help you achieve whatever it is you are trying to do.

New-MSMQueue.ps1

param (
$QueueName
)

[Reflection.Assembly]::LoadWithPartialName["System.Messaging"]

$NewMSMQ = [System.Messaging.MessageQueue]

foreach ($Q in $QueueName)
{
$qObject = $NewMSMQ::Create($Q,1)
$qObject.UseJournalQueue = $FALSE
$QueueLabel = $Q.TrimStart(".\")
$qObject.Label = $QueueLabel

$qObject.SetPermissions["Everyone",[System.Messaging.MessageQueueAccessRights]::FullControl, [System.Messaging.AccessControlEntryType]::Allow]
}

Purge-MSMQueue.ps1

param (
$QueueName
)

[Reflection.Assembly]::LoadWithPartialName["System.Messaging"]

If (!(test-path C:\scripts\MSMQlog))
{
new-item -path c:\scripts -name MSMQlog -itemtype directory
}

foreach ($Q in $Queuename)
{
    $MessageQueue = New-Object System.Messaging.MessageQueue $Q
    $MSGCount = $MessageQueue.GetAllMessages().Length

        IF($MSGCount)
            {
            $MessageQueue.Purge()
            }
        $date = get-date -Format ddMMyy-hhmm
        Out-File -filepath C:\scripts\MSMQlog\MSMQPurge.$date.log -InputObject "$Q has been purged of $MSGCount messages" -append
}

Don,

Thanks for the etiquette pointer - I’ll make a point of editing my questions instead of posting answers going forward.
I also appreciate your letting me know if there’s a spot for me to help correct the TechNet doc. I’m not currently in Connect. I’ll try pursuing the product support route. Never know - that may get some results.

Thanks,
Joel

Nick,

Thanks for posting these scripts. I’ll take a look, but I’m hoping to use the MSMQ cmdlets in PS4 to do everything I need to. There’s a Clear-MsmqQueue which will purge a queue, and the New-MsmqQueue for creating queue.
Thanks for sharing, though.

-Joel