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

如何通过PowerShell查看Hyper-V虚拟机标签?(Server Core 2019)

在Hyper-V Server Core 2019中用PowerShell筛选带特定标签的虚拟机

Windows Admin Center为Hyper-V虚拟机设置的标签,实际存储在虚拟机对象的ExtendedData属性中,对应的键名为Tag。以下是查看和筛选标签的具体方法:

查看单个虚拟机的标签

执行以下命令查看指定虚拟机的标签信息:

Get-VM -Name "你的虚拟机名称" | Select-Object Name, ExtendedData

如果该虚拟机已设置标签,ExtendedData字段会显示类似@{Tag="Production"}的内容。

筛选带有特定标签的所有虚拟机

单标签匹配

如果你的标签是单个值(如"Production"),使用以下脚本筛选:

# 替换为你要查找的目标标签
$targetTag = "Production"

# 获取所有符合条件的虚拟机名称
Get-VM | Where-Object {
    $_.ExtendedData.ContainsKey("Tag") -and $_.ExtendedData["Tag"] -eq $targetTag
} | Select-Object -ExpandProperty Name

多标签包含匹配

如果WAC中设置的是多个逗号分隔的标签(如"Production,Web"),要筛选包含某个特定标签的虚拟机,可使用以下脚本:

# 替换为你要查找的目标标签
$targetTag = "Production"

# 拆分多标签并匹配
Get-VM | Where-Object {
    $_.ExtendedData.ContainsKey("Tag") -and 
    ($_.ExtendedData["Tag"].Split(",") | ForEach-Object { $_.Trim() }) -contains $targetTag
} | Select-Object -ExpandProperty Name

注意事项

  • 运行PowerShell时需具备Hyper-V管理员权限
  • Hyper-V Server Core 2019原生支持Get-VM的ExtendedData属性,无需额外安装模块
  • 未设置标签的虚拟机不会包含Tag键,脚本中的ContainsKey判断可避免空值报错

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 08:20:53