For system, network and cloud administrators

How to delete all Azure resource groups that start with a pattern using Azure CLI and Azure Bash shell

In order to delete all resource groups that start with project01, for example, you’ll first need to make sure you’re in a Bash shell and not PowerShell. Then, type:

az group list --query "[?starts_with(name,'project01')].[name]" --output tsv | xargs -L1 bash -c 'az group delete --name $0 --no-wait --yes' 

As this command is executed asynchronously (because of the –no-wait parameter we gave), it means that even though after the execution of the command the shell will allow you to execute further commands it will mean that the resource groups haven’t been deleted just yet, as it will take a few minutes before the resource groups will actually be deleted.

Leave a Reply

Your email address will not be published. Required fields are marked *