title: Retrieve Azure Service Bus Shared Access Connection String via Powershell
body: <p>It's possible to retrieve the access key to an Azure storage account using Get-AzureRmStorageAccountKey from Powershell. How would I get hold of the access key to a shared access policy of an Azure Service Bus?</p>
  
  <p><strong>More clarification</strong></p>
  
  <p>This is what I get when I use the Get-AzureRmServiceBusNamespaceKey cmdlet:</p>
  
  <pre><code>PS C:\Windows\system32&gt; Login-AzureRmAccount -Credential $cred
  
  Environment           : AzureCloud
  Account               : ***redacted***
  TenantId              : ***redacted***
  SubscriptionId        : ***redacted***
  CurrentStorageAccount : 
  
  PS C:\Windows\system32&gt; Set-AzureRmContext -SubscriptionId ***redacted***
  
  Environment           : AzureCloud
  Account               : ***redacted***
  TenantId              : ***redacted***
  SubscriptionId        : ***redacted***
  CurrentStorageAccount : 
  
  
  PS C:\Windows\system32&gt; Get-AzureRmServiceBusNamespaceKey -ResourceGroup testresourcegroup -Name test-bus -AuthorizationRuleName SendPolicy
  Get-AzureRmServiceBusNamespaceKey : Run Login-AzureRmAccount to login.
  At line:1 char:1
  + Get-AzureRmServiceBusNamespaceKey -ResourceGroup testresourcegroup -Name    test-bus ...
  +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : InvalidOperation: (:) [Get-AzureRmServiceBusNamespaceKey], PSInvalidOperationException
  + FullyQualifiedErrorId :   InvalidOperation,Microsoft.Azure.Commands.ServiceBus.Commands.Namespace.GetAzure RmServiceBusNamespaceKey
  
  
  PS C:\Windows\system32&gt; Get-AzureRmStorageAccountKey -ResourceGroupName testresourcegroup -Name teststoragexxx
  
  Key1                                                                                                        Key2                                                                                                   
  ----                                                                                                    ----                                                                                                   
  ***redacted***                ***redacted***
  </code></pre>