skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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


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

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

    See also here:
    https://learn.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"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search