0
votes

I have a service bus Connectionstring like

Endpoint=sb://my-bus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<secret key>

I can use that in my .Net code to manage the service bus, like create/delete topics and subscriptions.

How can I achieve the same using Powershell?

Thanks

1

1 Answers

1
votes

As I know, it is not support to delete topic directly just with given connection string in Powershell cmd currently. But we could do that by including a reference the .NET assembly for Service Bus. The following is demo code:

$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."

enter image description here

If we could Login-AzureRmAccount, we could use Remove-AzureRmServiceBusTopic to do that.