skip to Main Content

I want to delete all the resource groups in a subscription in a single cli command. I used pipeline operator to delete all the resource groups:

(Get-AzResourceGroup | Remove-AzResourceGroup).

While azure deletes the groups sequentially, it prompts for confirmation for each resource group. Is there a way to force delete all resource groups in Azure cli without encountering the confirmation from the CLI.

2

Answers


  1. Please use -Force parameter to remove resource group without confirmation.

    From this link:

    Get-AzResourceGroup -Name "ContosoRG01" | Remove-AzResourceGroup -Force
    

    This command uses the Get-AzResourceGroup cmdlet to get the resource
    group ContosoRG01, and then passes it to Remove-AzResourceGroup by
    using the pipeline operator. The Force parameter suppresses the
    confirmation prompt
    .

    Login or Signup to reply.
  2. We can use this power shell script to delete all resource groups in a subscription.
    Delete All resource groups whose names match with the filter

    $filter = 'rg-devenvironment' 
    Get-AzResourceGroup | ? ResourceGroupName -match $filter | Remove-AzResourceGroup -AsJob -Force
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search