【问题标题】:Windows Service Bus 1.1: looking for Powershell script to delete topic/subscriptionWindows Service Bus 1.1:寻找 Powershell 脚本来删除主题/订阅
【发布时间】:2018-08-16 04:02:30
【问题描述】:

我想通过 power-shell 脚本删除 SB 主题及其订阅。

我可以使用 Microsoft.ServiceBus 命名空间和 NamespaceManager 类中可用的 C# 代码删除。

public void DeleteSubscription(string topicPath, string name);

但正在寻找 power-shell 脚本?

我得到了删除整个 SB 命名空间的脚本。

Remove-SBNamespace –Name 'ServiceBusDefaultNamespace' -Force

请建议可以删除单个主题及其订阅的脚本。谢谢!

我想使用一些 Azure 版本命令,这里是更新,

我正在使用命令Remove-AzureRmServiceBusTopic -NamespaceName SB-Example1 -TopicName SB-Topic_exampl1,它要求-ResourceGroup。现在对于本地服务总线,我认为我们不能通过任何`ResourceGroup,请建议

【问题讨论】:

    标签: c# powershell servicebus


    【解决方案1】:

    使用适当的方法登录并选择所需的订阅和资源组,然后继续使用 SB cmdlet。

    powerShell 的登录订阅资源组

    Write-Host -ForegroundColor Yellow "Login with your Azure Account"
    Add-AzureRmAccount
    Write-Host -ForegroundColor Yellow "Your available Subscriptions"
    Get-AzureRmSubscription | Format-List -Property Name, Id
    $subscriptions = @(Get-AzureRmSubscription | Select-Object -ExpandProperty Id)
    $flag = $true
    while ($flag) {
        Write-Host -ForegroundColor Green 'Enter target Subscription Id: ' -NoNewline
        $subscriptionId = Read-Host
        if ($subscriptions -contains $subscriptionId) {
            Select-AzureRmSubscription -SubscriptionId $subscriptionId
            Write-Output "yes"
            $flag = $false
            break
        }
        elseif ($flag -eq $true) {
            Write-Host "Enter valid Subscription Id"
        }
    }
        Write-Host -ForegroundColor Yellow `r`n'Your Available Resource Groups'
        Get-AzureRmResourceGroup | Select-Object -ExpandProperty ResourceGroupName
        $resourceGroups = @(Get-AzureRmResourceGroup | Select-Object -ExpandProperty ResourceGroupName)
        $flag = $true
        while ($flag) {
            Write-Host -ForegroundColor Green `r`n'Enter target Resource Group name: ' -NoNewline
            $resourceGroupName = Read-Host
            if ($resourceGroups -contains $resourceGroupName) {
                Set-AzureRmResourceGroup -Name $resourceGroupName -Tag @{}
                $flag = $false
                break
            }
            elseif ($flag -eq $true) {
                Write-Host `r`n"Enter valid Resource Group name"
            }
        }
    

    要删除主题,请使用Remove-AzureRmServiceBusTopic,您可以阅读有关它的信息here,要删除订阅,您可以使用Remove-AzureRmServiceBusSubscription,也有可用的文档here

    注意:确保您在模块列表中安装了 AzureRm.ServiceBus 模块,如果您没有,请从 Admin Powershell Install-Module -Name AzureRM.ServiceBus 运行此模块

    【讨论】:

    • @HariHaran...我没有使用 Azure 服务总线,而是使用本地 Windows 服务总线 1.1。这些 Azure 版本命令会起作用吗?
    • 我正在使用命令Remove-AzureRmServiceBusTopic -NamespaceName SB-Example1 -TopicName SB-Topic_exampl1,它要求-ResourceGroup。现在对于本地服务总线,我认为我们不能通过任何ResourceGroup,请建议
    • 登录到 Azure,在运行此命令之前选择订阅和资源组,它应该可以工作。我已经编辑了我的答案。请看一下。
    • 啊!我是 NOT 使用 Azure,感谢您的回答!我正在使用 Windows 服务总线 1.1
    • 是的,仅通过 powershell
    猜你喜欢
    • 1970-01-01
    • 2021-07-19
    • 2021-01-24
    • 2021-04-24
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多