How to set permissions on MSMQ Cluster queues?

纵然是瞬间 提交于 2020-01-24 21:25:10

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/10021440/how-to-set-permissions-on-msmq-cluster-queues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!