For system, network and cloud administrators

How to delete all Azure storage accounts that start with a pattern using Azure CLI and Bash shell

In order to delete all Azure storage accounts that start with mystorage, for example, you’ll first need to run a Bash shell instead of PowerShell. Then, type:

az storage account list --query "[?starts_with(name,'mystorage')].[name]" --output tsv | xargs -L1 bash -c 'az storage account delete --name $0 --yes'


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'