Search code examples
powershellmsmqcluster-computing

How to set permissions on MSMQ Cluster queues?


I've got a cluster with functioning private MSMQ 3.0 queues. I'm trying to programmatically set the permissions, but can't seem to connect via System.Messaging on the queues. The code below works just fine when working with local queues (and using .\ nomenclature for the local queue). How to programmatically set the permissions on the clustered queues?

Powershell code executed from the active node

function set-msmqpermission ([string] $queuepath,[string] $account, [string] $accessright)
{
    if (!([System.Messaging.MessageQueue]::Exists($queuepath))){
    throw "$queuepath could not be found."
}
$q=New-Object System.Messaging.MessageQueue($queuepath)
$q.SetPermissions($account,[System.Messaging.MessageQueueAccessRights]::$accessright,            
  [System.Messaging.AccessControlEntryType]::Set)
}
set-msmqpermission "clusternetworkname\private$\qa1ack" "UserAccount" "FullControl"

Exception calling "SetPermissions" with "3" argument(s): "Invalid queue path name." At line:30 char:19 + $q.SetPermissions <<<< ($account,[System.Messaging.MessageQueueAccessRights]::$accessright,
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException


Solution

  • From: http://winterdom.com/2011/10/using-powershell-with-clustered-msmq

    You have to set the cluster network name environment variable before using messageQueue.

    $env:_CLUSTER_NETWORK_NAME_ = 'myclusterMSMQ'
    [System.Messaging.MessageQueue]::Create('.\Private$\MyQueue')
    

    Adding the cluster network name to top of script should solve the problem

    Link to the full (simplistic - but works for simple creation and assignment of perms) script I provided as an answer to another question. https://stackoverflow.com/a/11268755/761599