For system, network and cloud administrators

How to delete all Azure managed disks that start with a pattern using Azure CLI and Bash shell

In order to be able to delete all Azure managed disks that start with mydisk, for example, you’ll first need to run the Azure Bash shell instead of PowerShell and then type:

az disk list --query "[?starts_with(name,'mydisk')].[name]" | xargs -L1 bash -c 'az disk delete --resource-group yourresourcegroup --name $0 --yes'


How to list all Azure managed disks using Azure CLI

In order to view all managed disks in Azure, type:

az disk list --output tsv


How to list all Azure managed disks that start with a pattern using Azure CLI

In order to view all managed disks that start with the disk name, type:

az disk list --query "[?starts_with(name,'disk')].name" --output tsv