4

I can successfully create a Shared Access Policy on the SB Namespace with PowerShell using:

New-AzureSBAuthorizationRule -Name "MyEHListenRule" -Namespace $AzureSBNameSpace -Permission Listen

However, when attempting to set a Shared Access Policy on a SB Queue according to this MSDN article using:

New-AzureSBAuthorizationRule -Name "Manage" -Namespace $AzureSBNameSpace -Permission $("Manage", "Listen", "Send") -EntityName $QName -EntityType Queue

Where:

[string]$AzureSBNameSpace = ronboksbeh 
[string]$QName =ronbokq0 

PowerShell returns:

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

Additionally there was a previous question about this cmdlet not working back in December 2014 and this question has still gone unanswered.

I am still struggling with this, so if anyone has ever gotten this cmdlet to work and could shed some light on what we might be doing incorrectly it would be greatly appreciated.

Community
  • 1
  • 1
  • Hello, I think this should be a bug in the code that has been fixed now. I am able to run your command successfully. I am using version 0.9.5. – Lichader Jul 28 '15 at 07:35

2 Answers2

1

I get the same error and use this so that I can choose which permissions to add

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

You can alter the code to set permissions on Queues by replacing topic with queue :-)

0

I faced the same problem with New-AzureSBAuthorizationRule, but I achieved my goal with this kind of script :

#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)
Johnny5
  • 6,664
  • 3
  • 45
  • 78