Search code examples
azureazure-cli

Azure CLI - List all subscriptions with tags


I need to list all subscriptions with:

Sub name, Sub ID, Status, Tags, Parent Management Group

I tried using:

az graph query -q "resourcecontainers | where type == 'microsoft.resources/subscriptions' | project id, name, subscriptionId, tags"

But it does not seem to have an option to list state or Management Group.

Is there a way list all of those properties at once?


Solution

  • To retrieve the list of all subscriptions with the Sub name, Sub ID, Tags, and Parent Management Group, you would typically need to combine data from multiple commands or queries since this information might not be available in a single query.

    For the subscriptions' information (Sub name, Sub ID, Tags), you can use the following query:

    az graph query -q "resourcecontainers | where type == 'microsoft.resources/subscriptions' | project id, name, subscriptionId, tags"
    

    enter image description here For the Status, if you're referring to the state of the subscription (like Enabled, Disabled, etc.), this is not directly available in the Azure Resource Graph. You may need to use Azure PowerShell or Azure CLI to list the state separately. The Azure CLI command az account list --query "[].{name:name, state:state}" can give you the name and state. output here

    If you need to combine this information, you might have to write a script that uses the output of multiple commands to create a consolidated view.

    References: