我可以使用PowerShell使用PowerShell在SB命名空间上成功创建共享访问策略:
New-AzureSBAuthorizationRule -Name "MyEHListenRule" -Namespace $AzureSBNameSpace -Permission Listen
但是,尝试根据此MSDN article使用以下内容在SB队列上设置共享访问策略时:
New-AzureSBAuthorizationRule -Name "Manage" -Namespace $AzureSBNameSpace -Permission $("Manage", "Listen", "Send") -EntityName $QName -EntityType Queue
其中:
[string]$AzureSBNameSpace = ronboksbeh
[string]$QName =ronbokq0
PowerShell返回:
New-AzureSBAuthorizationRule : Object reference not set to an instance of an object.
At line:1 char:1
+ New-AzureSBAuthorizationRule -Name "MyRule" -Namespace $AzureSBNameSpace -Permis ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureSBAuthorizationRule], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceBus.NewAzureSBAuthorizationRuleCommand
此外,有关此cmdlet之前的question在2014年12月无法恢复,此问题仍然无法解决。
我仍然在努力解决这个问题,所以如果有人让这个cmdlet工作,并且可以对我们可能做错的事情有所了解,那将非常感激。
答案 0 :(得分:1)
我得到相同的错误并使用它,以便我可以选择要添加的权限
function Create-AzureSBAuthorisationTopic
{
param
([Parameter (Mandatory = $true)]
[string] $Namespace,
[Parameter (Mandatory = $true)]
[string] $TopicName,
[Parameter (Mandatory = $true)]
[string]$RuleName,
[switch]$CanManage,
[switch]$CanListen,
[switch]$CanSend
)
$NamespaceManager = [Microsoft.ServiceBus.NamespaceManager]::CreateFromConnectionString($CurrentNamespace.ConnectionString);
$newkey = [Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule]::GenerateRandomKey()
#Strongly Typed Array
[Microsoft.ServiceBus.Messaging.AccessRights[]]$AccessRights =
New-Object -TypeName "System.Collections.Generic.List[Microsoft.ServiceBus.Messaging.AccessRights]" ;
if ($CanManage)
{
$AccessRights += [Microsoft.ServiceBus.Messaging.AccessRights]::Manage;
}
if ($CanListen)
{
$AccessRights += [Microsoft.ServiceBus.Messaging.AccessRights]::Listen;
}
if ($CanSend)
{
$AccessRights += [Microsoft.ServiceBus.Messaging.AccessRights]::Send;
}
$AuthorizationRule = [Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule]::new($RuleName,$newkey, $accessRights)
$AuthorizationRule
$topic = $NamespaceManager.GetTopic($TopicName)
$topic.Authorization.Add($AuthorizationRule)
$NamespaceManager.UpdateTopic($topic)
}
您可以通过将队列替换为队列来更改代码以设置队列权限: - )
答案 1 :(得分:0)
我遇到New-AzureSBAuthorizationRule
同样的问题,但我用这种脚本实现了我的目标:
#Create a namespace manager for your namespace
$ns = Get-AzureSBNamespace('yourservicebusnamespace')
$mngr = [Microsoft.ServiceBus.NamespaceManager]::CreateFromConnectionString($ns.ConnectionString)
#Create the desired access rule
[Microsoft.ServiceBus.Messaging.AccessRights[]]$rights = @([Microsoft.ServiceBus.Messaging.AccessRights]::Listen)
$rule = New-Object -TypeName Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule('rulename', $rights)
#Get the queue description, add the rule and update it.
$queue = $mngr.GetQueue('yourqueuename')
$queue.Authorization.Add($rule)
$mngr.UpdateQueue($queue)