2

Am able to create the queue with the below code,

$queuename = "samplequeue"
$CurrentNamespace = Get-AzureSBNamespace -Name "mynamespace"
$NamespaceManager = [Microsoft.ServiceBus.NamespaceManager]::CreateFromConnectionString($CurrentNamespace.ConnectionString);
$QueueDescription = New-Object -TypeName Microsoft.ServiceBus.Messaging.QueueDescription -ArgumentList $queuename
$NamespaceManager.CreateQueue($QueueDescription);

I am looking for powershell cmdlets to create/ manage Shared Access Policy for a ServiceBus Queue.

Am able to add it from the management portal.

enter image description here

Also tried the below cmdlet,

New-AzureSBAuthorizationRule -Name "readwritepolicy" -Namespace "mynamespace"-Permission $("Send") -EntityName "notsure" -EntityType "Queue"

which gives me the below error,

New-AzureSBAuthorizationRule : Object reference not set to an instance of an object.
At line:1 char:1
+ New-AzureSBAuthorizationRule -Name "readwritepolicy" -Namespace "mynamespace" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureSBAuthorizationRule], NullReferenceException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceBus.NewAzureSBAuthorizationRuleCommand

Am i doing anything wrong? What is EntityName ?

Pradebban Raja
  • 443
  • 5
  • 20
  • Adding the correct queue name does not help either. New-AzureSBAuthorizationRule -Name "myrule" -Namespace "mynamespace" -PrimaryKey $base64Key -Permission $("Send") -EntityName "myqueue" -EntityType "Queue" Get-AzureSBAuthorizationRule : Object reference not set to an instance of an object. At line:1 char:1 + Get-AzureSBAuthorizationRule -Namespace "mynamespace" -EntityName "myque ... + – Pradebban Raja Jul 09 '15 at 12:24

2 Answers2

0

I know this is a little old but it came up in my search and enabled me to succeed so I thought it worth sharing

I got it to work by adding to the below answer as shown as I was getting errors with the new-AzureSBAuthorisationRule cmdlet

$NamespaceManager.UpdateTopic($topic)

but I was adding to a topic so in this example it would be

$NamespaceManager.UpdateQueue($queuename)
-1

The EntityName parameter is the name of the queue you want to add the autorization rule to.

However, I'm not sure why the New-AzureSBAuthorizationRule cmdlet fails when you try to add a rule to a queue, but other people are reporting the same problem. As a workaround, you can try this:

$queuename = "yourqueue"
$CurrentNamespace = Get-AzureSBNamespace -Name "yournamespace"
$NamespaceManager = [Microsoft.ServiceBus.NamespaceManager]::CreateFromConnectionString($CurrentNamespace.ConnectionString);

$newkey = [Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule]::GenerateRandomKey()
[Microsoft.ServiceBus.Messaging.AccessRights[]] $accessRights  = [Microsoft.ServiceBus.Messaging.AccessRights]::Send
$AuthorizationRule = [Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule]::new("myRule",$newkey, $accessRights)

$queue = $NamespaceManager.GetQueue($queuename )
$queue.Authorization.Add($AuthorizationRule)
Dominic Betts
  • 2,306
  • 1
  • 18
  • 10
  • Thanks, however that does not solve the issue, and the question is still wider. – Pradebban Raja Jul 09 '15 at 12:23
  • Seems the method is not available in the AuthorizationRules calss. Method invocation failed because [Microsoft.ServiceBus.Messaging.AuthorizationRules] does not contain a method named 'new' – Pradebban Raja Jul 09 '15 at 16:23
  • It runs in my environment - do you know if you are using the latest version of the ServiceBus assemblies? Also, which line gives the error? – Dominic Betts Jul 10 '15 at 05:28
  • Line which gives error: $AuthorizationRule = [Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule]::new("myRule",$newkey, $accessRights) Am running on the latest Azure modules. Should i need to explicitly add any assemblies. – Pradebban Raja Jul 10 '15 at 14:26
  • Hmmh. I didn't add any assemblies explicitly. – Dominic Betts Jul 10 '15 at 16:06