powershell - 通过 Powershell 检索 Azure 服务总线共享访问连接字符串

标签 powershell azure azureservicebus

可以使用 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/

相关文章:

xml - 使用 PowerShell 更改 XML 中的项目(0)

powershell - 在 powershell 中获取过滤结果

通过 Powershell 注册 Azure AD 应用程序 : How to ensure the proper permissions?

session - Azure、SubscriptionClient.OnMessage 和 session

c# - Azure 服务总线队列 - 如何防止 IHostedService 立即处理队列消息

powershell - 我可以在 Windows Powershell ISE 中使用 "break when an exception is thrown"吗?

azure - 在 azure 上存储图像和视频的最佳方式

asp.net - 将 ASP.NET vNext 应用程序部署到 Azure 云服务

azure - 通过 VPN 连接到 Azure Database for Postgresql

c# - TopicClient.Send 有时需要很长时间才能发送消息