0

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

sppc42
  • 2,994
  • 2
  • 31
  • 49
  • Here is the [MSDN page for PowerShell cmdlets working with Azure Service Buses](https://learn.microsoft.com/en-us/powershell/resourcemanager/azurerm.servicebus/v0.0.2/azurerm.servicebus). Here is [the intro to installing the AzureRM module](https://learn.microsoft.com/en-us/powershell/azureps-cmdlets-docs/) – BenH Feb 23 '17 at 14:43
  • http://stackoverflow.com/questions/16662795/deleting-dead-topics-in-azure-service-bus – Lachie White Feb 24 '17 at 02:11

1 Answers1

1

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.

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47