How to delete all resources group in difference subscription at one button

ALVIN LEUNG (CLOUD-ISD-OOCLL/HKG) 166 Reputation points
2022-08-23T07:54:55.177+00:00

233935-image.png

I got same name resources group in different subscription. But portal does not allow me to one click delete them. Is there any method to do this bulk operation? Thanks

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,113 questions
Azure Resource Mover
Azure Resource Mover
An Azure service used for moving multiple resources between Azure regions.
200 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 96,441 Reputation points MVP
    2022-08-23T16:11:02.447+00:00

    Hi @ALVIN LEUNG (CLOUD-ISD-OOCLL/HKG) ,

    deleting all Resource Groups with the same name in different Azure Subscriptions is possible using PowerShell and the Az module (not "one button" but "one script with a few lines").
    You need to select the Azure Subscription one after the other and check if the Resource Group is existing.
    Maybe this PowerShell script is helpful to get started:

    $rg2Delete = "test-rg"  
    Get-AzSubscription | ForEach-Object {  
        Select-AzSubscription $_  
        $rgObject = Get-AzResourceGroup -Name $rg2Delete -ErrorAction SilentlyContinue  
        if ($rgObject) {  
            Remove-AzResourceGroup -Name $rg2Delete -WhatIf  
        }  
        else {  
            Write-Output "RG $rg2Delete not found in $($_.Name)"  
        }  
    }  
    

    Just remove the -WhatIf parameter in line 6 and the resource groups will be deleted.
    With the parameter -WhatIf it shows what would happen if the cmdlet Remove-AzResourceGroup runs. But it's not removing anything.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    2 people found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Mohammed Altamash Khan 2,076 Reputation points
    2022-08-23T08:14:29.04+00:00

    Hi @ALVIN LEUNG (CLOUD-ISD-OOCLL/HKG)

    The bulk delete option is highlighted , the good thing is your RG name is common so you just type few words in search and click on Check box next to NAME as shown in image attached and delete in 1 Go.

    If the check box for selecting all option doesn't work , try different browser , or raise a support case with MS.

    233865-image.png

    ---------If you find this answer helpful, kindly accept the answer ---------


  2. Limitless Technology 39,356 Reputation points
    2022-08-23T14:50:05.65+00:00

    Hello there,

    You can try the Powershell script

    Remove-AzResourceGroup -Name ExampleResourceGroup

    When you delete a resource group, the Resource Manager determines the order to delete resources. It uses the following order:

    All the child (nested) resources are deleted.

    Resources that manage other resources are deleted next. A resource can have the managedBy property set to indicate that a different resource manages it. When this property is set, the resource that manages the other resource is deleted before the other resources.

    The remaining resources are deleted after the previous two categories.

    Azure Resource Manager resource group and resource deletion https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/delete-resource-group?tabs=azure-powershell

    ---------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments