可以使用 Powershell 中的 Get-AzureRmStorageAccountKey 检索 Azure 存储帐户的访问 key 。如何获取 Azure 服务总线共享访问策略的访问 key ?
更多说明
这是我使用 Get-AzureRmServiceBusNamespaceKey cmdlet 时得到的结果:
PS C:\Windows\system32> Login-AzureRmAccount -Credential $cred
Environment : AzureCloud
Account : ***redacted***
TenantId : ***redacted***
SubscriptionId : ***redacted***
CurrentStorageAccount :
PS C:\Windows\system32> Set-AzureRmContext -SubscriptionId ***redacted***
Environment : AzureCloud
Account : ***redacted***
TenantId : ***redacted***
SubscriptionId : ***redacted***
CurrentStorageAccount :
PS C:\Windows\system32> 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> Get-AzureRmStorageAccountKey -ResourceGroupName testresourcegroup -Name teststoragexxx
Key1 Key2
---- ----
***redacted*** ***redacted***
最佳答案
不能使用Get-AzureRmStorageAccountKey,但您可以使用Get-AzureRmServiceBusNamespaceKey
$resourceGroup = "myResourceGroup"
$serviceBusName ="myservicebusname"
$policyName = "policyname"Get-AzureRmServiceBusNamespaceKey -ResourceGroup $resourceGroup -Name $serviceBusName -AuthorizationRuleName $policyName
这将返回整个对象,因此您可以将其传递到变量中并从中获取键或连接字符串。
关于powershell - 通过 Powershell 检索 Azure 服务总线共享访问连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41809370/