gpt4 book ai didi

powershell - Set-MsmqQueueACL - 允许 - 不能按照文档使用列表?

转载 作者:行者123 更新时间:2023-12-04 19:31:12 25 4
gpt4 key购买 nike

我正在尝试使用 Powershell v5.1 (Win2k16) 在 Msmq 队列上设置 ACL - 但即使我正在关注文档 - 我仍然收到错误消息。

Get-MsmqQueue -Name "s009_ClientsServiceBus" -QueueType Private | Set-MsmqQueueAcl -UserName "domain.com\WfxServiceBus" -Allow Peek,Write

错误:
Set-MsmqQueueACL : Cannot convert 'System.Object[]' to the type
'System.Nullable`1[Microsoft.Msmq.PowerShell.Commands.MessageQueueAccessRights]' required by parameter 'Allow'. Specified method is
not supported.
At line:1 char:128
+ ... t-MsmqQueueAcl -UserName "domain.com\WfxServiceBus" -Allow Peek,Write
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-MsmqQueueACL], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Msmq.PowerShell.Commands.SetMSMQQueueACLCommand

Docs显示以下示例:
Get-MsmqQueue –Name Order* –QueueType Private | Set-MsmqQueueAcl –UserName “REDMOND\madmax” –Allow Delete,Peek,Receive,Send –Deny TakeOwnership

运行它(授予某些参数对我的环境不正确,但同样的错误)...
PS C:\Users\user> Get-MsmqQueue -Name Order* -QueueType Private | Set-MsmqQueueAcl -UserName "REDMOND\madmax" -Allow Delete,Peek,Receive,Send -Deny TakeOwnership 
Set-MsmqQueueACL : Cannot convert 'System.Object[]' to the type
'System.Nullable`1[Microsoft.Msmq.PowerShell.Commands.MessageQueueAccessRights]' required by parameter 'Allow'. Specified method is
not supported.
At line:1 char:100
+ ... cl -UserName "REDMOND\madmax" -Allow Delete,Peek,Receive,Send -Deny T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-MsmqQueueACL], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Msmq.PowerShell.Commands.SetMSMQQueueACLCommand

所以看起来文档已经过时了,或者发生了一些变化......问题是 - 我该如何使用 Powershell 做我需要做的事情?我尝试了很多组合,例如:
.... -Allow "Peek,Send"
.... -Allow "Peek","Send"
.... -Allow 'Peek,Send'

等等..

如果我只包含一个选项,即:“发送”或“查看”,那么它可以正常工作,但我无法根据文档发送一系列权限。

谢谢!

更新 - 使用 -Allow "Peek, Send":
    PS C:\Users\meaton> Get-MsmqQueue -Name "s009_ClientsServiceBus" -QueueType Private | Set-MsmqQueueAcl -UserName "domain.com\WfxServic
eBus" -Allow "Peek,Write"
Set-MsmqQueueACL : Cannot bind parameter 'Allow'. Cannot convert value "Peek,Write" to type
"Microsoft.Msmq.PowerShell.Commands.MessageQueueAccessRights". Error: "Unable to match the identifier name Peek,Write to a valid
enumerator name. Specify one of the following enumerator names and try again:
DeleteMessage, PeekMessage, ReceiveMessage, WriteMessage, DeleteJournalMessage, ReceiveJournalMessage, SetQueueProperties,
GetQueueProperties, DeleteQueue, GetQueuePermissions, GenericWrite, GenericRead, ChangeQueuePermissions, TakeQueueOwnership,
FullControl"
At line:1 char:128
+ ... MsmqQueueAcl -UserName "domain.com\WfxServiceBus" -Allow "Peek,Write"
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-MsmqQueueACL], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Msmq.PowerShell.Commands.SetMSMQQueueACLCommand

根据错误将其更改为“PeekMessage,SendMessage”会产生完全相同的错误:
...Set-MsmqQueueACL : Cannot bind parameter 'Allow'. Cannot convert value "PeekMessage,WriteMessage" to type
"Microsoft.Msmq.PowerShell.Commands.MessageQueueAccessRights" due to enumeration values that are not valid. Specify one of....

最佳答案

文档可能缺少引号;期待 an enum that supports bitfields ,所以很可能你会这样做(我的 2016 PS 5.1 机器上没有 msmq cmdlet 或类型,所以我无法测试),使用按位 or :

$allows = [Microsoft.Msmq.PowerShell.Commands.MessageQueueAccessRights]::Peek -bor
[Microsoft.Msmq.PowerShell.Commands.MessageQueueAccessRights]::Send -bor
[Microsoft.Msmq.PowerShell.Commands.MessageQueueAccessRights]::Receive

Set-MsmqQueueAcl -UserName "REDMOND\madmax" -Allow $allows

它应该通过将所有值放在引号中(即,不是数组,其中包含逗号的字符串)来工作,但是您说您尝试过这种方式但它不起作用;这是否产生了不同的错误?

关于powershell - Set-MsmqQueueACL - 允许 - 不能按照文档使用列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43596766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com