创建服务总线队列的授权时出现新的AzureSBAuthorizationRule错误

时间:2014-11-27 13:47:46

标签: powershell azure azureservicebus azure-powershell azure-servicebus-queues

我使用New-AzureSBAuthorizationRule为Azure Service Bus队列创建新的共享访问策略。见下面的命令......

New-AzureSBAuthorizationRule -EntityName abcdef -EntityType Queue -Permission Listen  -Name "abcdef_reader" -Namespace abcdefnamespace

但每次我运行时都会收到以下错误:

New-AzureSBAuthorizationRule : Object reference not set to an instance of an object.
At line:1 char:1
+ New-AzureSBAuthorizationRule -EntityName abcdef -EntityType Queue -Permission ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureSBAuthorizationRule], NullReferenceException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceBus.NewAzureSBAuthorizationRuleCommand

如果我删除EntityName和EntityType,即能够为服务总线而不是队列创建策略,我可以毫无问题地运行New-AzureSBAuthorizationRule。

我做错了什么?

2 个答案:

答案 0 :(得分:0)

我得到同样的错误并使用

            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 :(得分:-1)

你是否可能遗漏了-Permission参数的一些语法?以下是MSDN上给出的PS命令行示例:

C:\ PS> New-AzureSBAuthorizationRule -Name MyRule -Namespace MyNamespace -Permission $(“Manage”,“Listen”,“Send”) -EntityName MyEntity -EntityType Queue -PrimaryKey P + LL / Mnd2Z9sj5hwMrRyAxQDdX8RHfbdqU2eIAqs1rc =

您的参数看起来应该是 -Permission $(“Listen”)

如果有帮助,请告诉我们。

此致 赛斯曼海姆 Azure Doc Team