0

我使用 New-AzureSBAuthorizationRule 为 Azure 服务总线队列创建新的共享访问策略。请参阅下面的命令...

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,即为服务总线而不是队列创建策略。

我究竟做错了什么?

4

2 回答 2

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)
            }

您可以通过将主题替换为队列来更改代码以设置队列权限:-)

于 2016-01-21T19:56:57.620 回答
-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")

请让我们知道这是否有帮助。

问候, Seth Manheim Azure Doc 团队

于 2014-12-01T23:31:31.637 回答