You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求编写KQL查询:获取资源组名及拆分标签为列生成报表

KQL 查询实现资源组标签拆分报表

基础方案:自动拆分所有标签为独立列

Resources
| where type == "microsoft.resources/resourcegroups" // 仅筛选资源组数据
| project 
    SubscriptionName = subscriptionName,
    ResourceGroupName = name,
    Tags
| evaluate bag_unpack(Tags) // 核心:将动态标签对象拆分为键值对列

关键说明

  • 依赖Azure Resource Graph的Resources表,确保查询环境支持该数据源(比如Azure Resource Graph Explorer)。
  • bag_unpack(Tags)会自动识别所有标签键,为每个标签生成单独列,无对应标签的资源组会显示null。
  • 原始标签字段可保留也可移除,根据报表需求调整project语句。

可选:仅拆分指定标签(避免列过多)

如果只需要特定标签(比如Environment、CostCenter),可以手动提取:

Resources
| where type == "microsoft.resources/resourcegroups"
| project 
    SubscriptionName = subscriptionName,
    ResourceGroupName = name,
    Environment = tostring(Tags.Environment),
    CostCenter = tostring(Tags.CostCenter)

注意点

  • 若标签值为复杂类型(如数组),可通过tostring()转换为字符串格式。
  • 订阅名称字段subscriptionName仅在Resource Graph数据源中可用,无需额外关联订阅表。

内容的提问来源于stack exchange,提问作者Dave Gaitan Escobar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 07:58:11