anon
anon

Reputation:

How to delete all resource groups forcibly without prompt for confirmation using Azure CLI cmdlets?

Found the similar Question but answer is in Azure PowerShell.

Tried the below cmdlet to delete all resource groups in particular location:

az group list --query "[?location=='westus']".name -o tsv | xargs -otl az group delete -n

It is asking me to prompt for every resource group deletion.

Also tried adding the flag -y by reading this MS Doc,

az group list --query "[?location=='westus']".name -o tsv | xargs -otl az group delete -n -y

Error:

az group delete -n -y rg-105
argument --name/-n/--resource-group/-g: expected one argument

Upvotes: 1

Views: 1709

Answers (2)

karunakar bhogyari
karunakar bhogyari

Reputation: 679

Here I am deleting all resource groups in two locations using OR(||) operator and specified -y for running command without user consent or confirmation.

az group list --query "[?location=='centralindia'|| location=='eastus']".name -o tsv | xargs -otl az group delete -y -n

Upvotes: 0

Gaurav Mantri
Gaurav Mantri

Reputation: 136146

Please try the following:

az group list --query "[?location=='westus']".name -o tsv | xargs -ot -n 1 az group delete -y -n

Reference: https://github.com/Azure/azure-cli/issues/1398#issuecomment-276135930

Upvotes: 2

Related Questions