Module 1: Assignment - 4

Tasks To Be Performed: Use Azure CLI and Azure PowerShell to:

  1. Delete all the resource groups in West US region using one command

Continuing from Assignment 3: Module 1

To delete all resource groups in the West US region I use the following command:

az group list --query "[?location=='westus'].name" -o tsv | xargs -I {} az group delete --name {} --yes --no-wait

az group list --query "[?location=='westus'].name" -o tsv lists all resource groups and filters them to only include those in the “West US” region, outputting only their names in a tab-separated values format.

xargs -I {} az group delete --name {} --yes --no-wait takes each name and uses it to run the az group delete command, which deletes the resource group. The --yes flag bypasses the confirmation prompt, and the --no-wait flag makes the command return immediately without waiting for the deletion to complete.

To verify deletion:

az group list --query "[?location=='westus']" --output table

Success