Search code examples
azurekqlazure-resource-graph

Kusto get resourcegroups and subscription information


How can I get resource group name, subscription name and id for all the resource groups?

I can get all resourcegroups with

Resources| distinct resourceGroup

But if I add "id" in there I get same resourcegroup multiple times.

Resources | distinct resourceGroup, id

Solution

  • I understand, you want to pull the subscription Name, resource group name, id using the resource graph explorer. you can use the below KQL query.

    resourcecontainers 
    | where type == "microsoft.resources/subscriptions" 
    | join ( resourcecontainers | where type == "microsoft.resources/subscriptions/resourcegroups") on subscriptionId 
    | distinct name,name1,id1 
    | project SubscriptionName=name,resourceGroupName=name1, resourceGroupId=id1