One thing I tend to forget is how powerful azure cli is and how many things can be done way faster through this tool. So, for example, if you want to delete all files in an Azure Storage Account at once, a fast and easy way to do just that is by using the delete-batch command from Azure CLI.

Run the following command:

az storage blob delete-batch --account-key <storage_account_key> --account-name <storage_account_name> --source <container_name>

where:

  • <storage_account_key> is the Primary or Secondary key of your storage account and must be used in conjunction with storage account name,
  • <storage_account_name> is the name of your storage name and
  • <container_name> is the container name you want to delete files from.

and in a few seconds all your files will be deleted from the specified azure storage container.

Errors

If you get an error in regards to Blob Snapshots like this one, This operation is not permitted because the blob has snapshots. ErrorCode: SnapshotsPresent, add the --delete-snapshots with inlcude or only parameter:

az storage blob delete-batch --account-key <storage_account_key> --account-name <storage_account_name> --source <container_name> --delete-snapshots include

Retrieve Storage Account Id

If you want to retrieve Storage Account key, there are two options. One from the portal and the other one from command line using the following command:

az storage account keys list --subscription <subscription_id> -n <storage_account_name> --query [].{ID:value} --output table

where:

  • <subscription_id> is the subscription id that your storage account is using,
  • <storage_account_name> is the name of your storage account,
  • --query is used to fetch only the data you need from the results and
  • --output table is to display results in a table format

Categorized in: