Skip to content

Latest commit

 

History

History

tagQueries

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Query Azure Resources by Tags

Purpose

To provide examples on querying resources in Azure by their Tags.

Get all tag Key Value pairs

resources 
| where isnotempty(tags)
| where tags !has "hidden-"
| mv-expand tags
| extend tagName = tostring(bag_keys(tags)[0])
| extend tagValue = tostring(tags[tagName])

Alternate way to Expand all Tags

resources
| where isnotempty(tags)
| where tags !has "hidden-"
| mv-expand bagexpansion=array tags limit 400
| extend tagName = tags[0], tagValue = tags[1]

Summarize Count of resources by Tag name

resources 
| where isnotempty(tags)
| where tags !has "hidden-"
| mv-expand tags
| extend tagName = tostring(bag_keys(tags)[0])
| extend tagValue = tostring(tags[tagName])
| summarize count() by tagName
| order by ['count_'] desc

Summarize Count of resources for each Tag name and value

resources 
| where isnotempty(tags)
| where tags !has "hidden-"
| mv-expand tags
| extend tagName = tostring(bag_keys(tags)[0])
| extend tagValue = tostring(tags[tagName])
| summarize count() by tagName, tagValue
| order by ['count_'] desc

Summarize Count of Resource Types by Tag name and value

resources 
| where isnotempty(tags)
| where tags !has "hidden-"
| mv-expand tags
| extend tagName = tostring(bag_keys(tags)[0])
| extend tagValue = tostring(tags[tagName])
| summarize count() by type, tagName, tagValue 
| order by ['count_'] desc