我有一个服务总线连接字符串,比如
Endpoint=sb://my-bus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<secret key>我可以在我的.Net代码中使用它来管理服务总线,比如创建/删除主题和订阅。
如何使用Powershell实现相同的功能?
谢谢
发布于 2017-02-24 11:01:21
据我所知,目前Powershell cmd还不支持直接使用给定的连接字符串删除主题。但是我们可以通过including a reference the .NET assembly for Service Bus来实现。以下是demo代码:
$path = "C:\xx\Microsoft.ServiceBus.dll" # The path of the Microsoft.ServiceBus.dll
$topicName = "topic1"
$connectionString = "xxxxxxxxxxx"
Import-Module $path
Write-Output "The [Microsoft.ServiceBus.dll] assembly has been successfully added to the script."
$NamespaceManager= [Microsoft.ServiceBus.NamespaceManager]::CreateFromConnectionString($connectionString);
Write-Output "NamespaceManager has been successfully created."
$NamespaceManager.DeleteTopic($topicName)
Write-Output "$topicName has been successfully deleted."

如果我们可以登录-AzureRmAccount,我们就可以使用Remove-AzureRmServiceBusTopic来做到这一点。
https://stackoverflow.com/questions/42417408
复制相似问题