0

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
Kamsiinov
  • 1,315
  • 2
  • 20
  • 50
  • What do you mean *if I add "id" in there*? Can you post the query with the id? – Peter Bons Jun 26 '23 at 10:58
  • 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 – VenkateshDodda Jun 26 '23 at 17:22
  • that is exactly what I need. could you submit it as an answer? – Kamsiinov Jun 27 '23 at 03:50
  • @Kamsiinov I have posted the above comment as an answer. – VenkateshDodda Jun 27 '23 at 04:01

1 Answers1

1

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
VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12