Azure CLI – Deleting Resources

Azure CLI is really handy for all sorts of tasks. When I build solutions, POCs and environments and I want to tear down the resources I like to use Azure CLI over the Portal. Below will show you the commands I use.

First – Activate Azure CLI with the Cloud shell icon

This will load up the shell where you can select from PowerShell or Bash. I will use bash to list the resource group(s), then I issue the delete. I will target the following Resource Group.

So once the shell has loaded I enter a query to confirm the right resource group has been selected then the delete.

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

Because this is done with nowait you can keep using the CLI for other tasks, re-checking the portal you will see a few minutes later that the resource group has gone.

Leave a Reply