Khursheed
Khursheed

Reputation: 373

Delete list of Azure Resource Groups in a subscription without confirmation using Azure ClI

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.

Upvotes: 0

Views: 1185

Answers (2)

karunakar bhogyari
karunakar bhogyari

Reputation: 679

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

Upvotes: 2

Gaurav Mantri
Gaurav Mantri

Reputation: 136146

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.

Upvotes: 1

Related Questions