Home > Blockchain >  I need to list all resources in all subscriptions
I need to list all resources in all subscriptions

Time:06-28

I need to list all resources in all RGRPs on all subscriptions. all what is there basically.

I try to do it with regex but does not work.

CodePudding user response:

You can use a resource graph query (kusto/kcl) for that

Resources
| project name, type, location
| order by name asc

See also here: https://docs.microsoft.com/en-us/azure/governance/resource-graph/samples/starter?tabs=azure-cli#list-resources

PowerShell:

Search-AzGraph -Query "Resources | project name, type, location | order by name asc"

CodePudding user response:

Get all resources on all subscriptions:

#! /bin/bash 
for sub in $(az account list --query [].name -o tsv); do 
    az resource list -o tsv --subscription $sub 2>/dev/null 
done

Check if your resource exists and print subscription of it

#! /bin/bash 
for sub in $(az account list --query [].name -o tsv); do 
    az resource list -o tsv --subscription $sub 2>/dev/null --query [].name -o tsv 2>/dev/null | grep -i $1 && echo "SUBSCRIPTION:  $sub" && exit
done

Let me know if there is simpler way.

Cheers

  • Related