3

Is it possible to get Azure Service Bus primaryConnectionString with AZ CLI?

Input parameters:

  1. Resource Group
  2. Service Bus Name
Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
qwazer
  • 7,174
  • 7
  • 44
  • 69

2 Answers2

16

Years later it's now supported. In case anyone else stumbles upon this question like me, it can be done this way:

az servicebus namespace authorization-rule keys list --resource-group myresourcegroup --namespace-name mynamespace --name RootManageSharedAccessKey --query primaryConnectionString -o tsv
Keisha W
  • 686
  • 6
  • 17
1

For now, Azure CLI 2.0 does not support service bus. You could use az -h to check. Power Shell and Azure CLI 1.0(asm mode) support service bus now.

You could use Power Shell to get primary ConnectionString.

$CurrentRule = Get-AzureRmServiceBusNamespaceAuthorizationRule -ResourceGroup $ResGrpName -NamespaceName $Namespace -AuthorizationRuleName $AuthRule
$AuthRule=$CurrentRule.Name
(Get-AzureRmServiceBusNamespaceKey -ResourceGroup shuibus -NamespaceName shuitest -AuthorizationRuleName $AuthRule).PrimaryConnectionString

More information please refer to this link.

Update:

On a Linux VM, you could use this Rest API to automation generate connectionstring.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ServiceBus/namespaces/{namespaceName}/AuthorizationRules/{authorizationRuleName}/listKeys?api-version=2015-08-01
Shui shengbao
  • 18,746
  • 3
  • 27
  • 45