Search code examples
kqlazure-resource-graph

KQL Query to retrieve Subscription Name, Resource group name, and Tags sepparated into columns


I would like to retrieve all the resource group names with their corresponding tags and values to show them as a report, like this

enter image description here

I have tried queries to split the tags into columns without success.

Can anyone please help me?


Solution

  • To retrieve all the resource group names with their corresponding tags and values to show them as a report you can use extend, by using this fields can be taken which are present in tags, CreatedBy is a field stored in tags and name the field in the way to be viewed in the report. createdBy is name of the field this can be called by using [tags].<field name in tags>. So, the Tags can be separated into columns.

    Below query is used to separate tags into columns:

    resources 
    | project 
      subscriptionId, 
      resourceGroup, 
      name, 
      type, 
      tags
    | extend 
      createdBy = ['tags'].CreatedBy, 
      createdDate = ['tags'].CreatedDate, 
      owningTeam = ['tags'].OwningTeam, 
      reason = ['tags'].Reason
    

    Output:

    enter image description here