If you manage multiple Azure subscriptions you’ve probably found yourself running az account set over and over. Here’s a better way.
Loop through all subscriptions and list resource groups in each:
for sub in $(az account list --query "[].id" -o tsv); do
echo "=== Subscription: $sub ==="
az account set --subscription "$sub"
az group list --query "[].{Name:name, Location:location}" -o table
doneWant to find a specific resource across all subscriptions? Swap the inner command:
for sub in $(az account list --query "[].id" -o tsv); do
az account set --subscription "$sub"
az resource list --query "[?contains(name, 'myapp')].{Name:name, Sub:'$sub'}" -o table
donePro tip: For read-only queries across subscriptions, Azure Resource Graph is even faster:
az graph query -q "Resources | where name contains 'myapp' | project name, subscriptionId, resourceGroup" -o table