【问题标题】:Getting Operation System name from Get-VM从 Get-VM 获取操作系统名称
【发布时间】:2015-07-27 14:25:42
【问题描述】:

如何使用 PowerShell 从 Hyper-V 获取虚拟机的操作系统名称?

我试过了

get-vm

但是这个字段不见了。

【问题讨论】:

  • get-vm | select *这样的东西呢
  • 是的。它显示一个虚拟机的所有信息,但没有关于操作系统的信息
  • 我不确定这些信息是否可以从虚拟机的“外部”获得。您可以尝试here 之类的方法,即使用 WMI 查询“进入”正在运行的 VM 以获取该信息 - 当然具有所需的权限。
  • @Christian.K 从看起来这似乎是我见过的唯一路线。取决于您的虚拟机环境和正在运行的来宾类型,这很笨拙。很高兴 VMware 提供来宾操作系统属性。

标签: powershell operating-system virtual-machine hyper-v


【解决方案1】:

如果您使用虚拟机管理器,您可以运行类似 get-vm |ft 名称,操作系统 操作系统的 VMM 中的数据通常是正确的,但在极少数情况下可能会显示为丢失或不正确。

【讨论】:

    【解决方案2】:

    这可以从客人内在交换项目中检索到。

    # Filter for parsing XML data
    filter Import-CimXml 
    { 
       # Create new XML object from input
       $CimXml = [Xml]$_ 
       $CimObj = New-Object -TypeName System.Object 
    
       # Iterate over the data and pull out just the value name and data for each entry
       foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY[@NAME='Name']")) 
          { 
             $CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE 
          } 
    
       foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY[@NAME='Data']")) 
          { 
             $CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE 
          } 
    
       # Display output
       $CimObj 
    } 
    
    # Prompt for the Hyper-V Server to use
    $HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)"
    
    # Prompt for the virtual machine to use
    $VMName = Read-Host "Specify the name of the virtual machine"
    
    # Get the virtual machine object
    $query = "Select * From Msvm_ComputerSystem Where ElementName='" + $VMName + "'"
    $Vm = gwmi -namespace root\virtualization\v2 -query $query -computername $HyperVServer
    
    # Get the KVP Object
    $query = "Associators of {$Vm} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent"
    $Kvp = gwmi -namespace root\virtualization\v2 -query $query -computername $HyperVServer
    
    Write-Host
    Write-Host "Guest KVP information for" $VMName
    
    # Filter the results
    try {
        $Kvp.GuestIntrinsicExchangeItems | Import-CimXml | where Name -eq "FullyQualifiedDomainName"
    }
    catch {
        Write-Host "Not found"
    }
    

    来自Ben Armstrong’s Virtualization Blog

    【讨论】:

      猜你喜欢
      • 2016-10-31
      • 2015-05-25
      • 1970-01-01
      • 2017-06-15
      • 2019-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多