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

如何通过Azure CLI/PS/KQL获取Linux虚拟机操作系统版本

获取Azure Linux虚拟机操作系统详细版本的方法

Azure门户中显示的Linux虚拟机操作系统版本(如Linux (centos 7.9.2009))来自虚拟机的实例视图(Instance View),而非存储配置中的镜像引用字段(后者对部分Linux镜像可能为空)。以下是通过CLI、PowerShell和Resource Graph KQL获取该信息的具体方法:

一、Azure CLI方法

使用--show-details参数拉取实例视图数据,直接提取OS名称和版本:

az vm list --query '[].{ Name:name, OS类型:storageProfile.osDisk.osType, 操作系统详情:instanceView.osName + " (" + instanceView.osVersion + ")"}' --show-details

该命令会同时返回Windows和Linux虚拟机的信息,Linux实例的输出格式将与Azure门户一致。

二、PowerShell方法

通过-Status参数获取实例视图,拼接OS名称和版本字段:

Get-AzVM -Status | Select-Object Name, 
    @{Name='操作系统详情'; Expression={$_.OSName + " (" + $_.OSVersion + ")"}},
    OSType

执行后会输出包含虚拟机名称、完整OS信息和系统类型的结果。

三、Resource Graph KQL查询

在Azure Resource Graph中,从虚拟机资源的instanceView属性提取数据并拼接:

resources
| where type == "microsoft.compute/virtualmachines"
| project 
    虚拟机名称 = name,
    系统类型 = properties.storageProfile.osDisk.osType,
    OS名称 = properties.instanceView.osName,
    OS版本 = properties.instanceView.osVersion
| extend 操作系统详情 = strcat(OS名称, " (", OS版本, ")")
| project 虚拟机名称, 系统类型, 操作系统详情

此查询可批量检索所有虚拟机的OS详细信息,包括Linux实例的版本数据。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 10:05:35