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

Azure Graph Explorer查询已安装SQL Server的VM问题求助

Azure Graph Explorer查询SQL Server虚拟机优化方案

原查询的问题根源

你当前的查询仅筛选了microsoft.sqlvirtualmachine/sqlvirtualmachines类型的资源,这类资源是已注册到Azure SQL VM资源提供程序的虚拟机。但如果是手动安装SQL Server、未通过Azure SQL VM资源提供程序注册的虚拟机,不会出现在这个结果集里,这就是列表缺失的核心原因。

优化方案1:覆盖所有安装SQL Server的虚拟机(含未注册)

通过结合虚拟机资源和来宾配置检测,能获取所有安装了SQL Server的VM,无论是否注册:

// 获取所有虚拟机,标记是否有SQL相关扩展
resources
| where type == "microsoft.compute/virtualmachines"
| extend hasSqlExtension = array_length(properties.extensions) > 0 and any(properties.extensions, x => x.properties.publisher == "Microsoft.SqlServer.Management")
| project vmId = id, vmName = name, resourceGroup, location, subscriptionId = tolower(subscriptionId), hasSqlExtension
// 关联来宾配置,确认SQL Server实例存在
| join kind=leftouter (
    guestConfigurationAssignments
    | where properties.configuration.name contains "SQLServer"
    | extend vmId = properties.targetResourceId
    | project vmId, sqlDetected = true
) on vmId
// 筛选出确实安装SQL Server的VM
| where hasSqlExtension or sqlDetected == true
// 关联订阅名称
| join kind=inner (
    resourcecontainers
    | where type == "microsoft.resources/subscriptions"
    | extend subscriptionId = tolower(extract("subscriptions/([^/]+)", 1, id))
    | project subscriptionId, subscriptionName = name
) on subscriptionId
| project subscriptionName, vmName, resourceGroup, location, hasSqlExtension, sqlDetected

优化方案2:获取SQL Server版本及CU信息(针对已注册VM)

对于已注册到SQL VM资源提供程序的机器,可以直接从资源中提取版本和CU(累积更新)信息:

resources
| where type == "microsoft.sqlvirtualmachine/sqlvirtualmachines"
| extend 
    sqlVersion = properties.sqlServerVersion,
    sqlCU = properties.sqlServerPatchLevel,
    licenseType = properties.sqlServerLicenseType
| project id, name, resourceGroup, location, sqlVersion, sqlCU, licenseType, subscriptionId = tolower(subscriptionId)
| join kind=inner (
    resourcecontainers
    | where type == "microsoft.resources/subscriptions"
    | extend subscriptionId = tolower(extract("subscriptions/([^/]+)", 1, id))
    | project subscriptionId, subscriptionName = name
) on subscriptionId
| project subscriptionName, name, resourceGroup, location, sqlVersion, sqlCU, licenseType

补充说明

  • 未注册的VM无法直接通过Graph Explorer获取SQL Server版本和CU信息,需要依赖Azure Monitor Agent收集来宾指标或自定义扩展来获取这类数据。
  • 如果你的环境中所有SQL Server VM都应该注册到SQL VM资源提供程序,建议检查未注册的VM并完成注册,这样能更方便地统一管理和获取详细信息。

内容的提问来源于stack exchange,提问作者Zarty

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 10:18:17