automation - Is there a way to get VMs Operating System name from Hyper-V using powershell? -


i'm writing script on hyper-v host getting vms guest informations. there way vms operating system name hyper-v using powershell?

there several examples using (get-wmiobject win32_operatingsystem -computername $vmname).name should information directly hyper-v because of domain restrictions.

also i'm using hyper-v module of powershell couldn't see cmdlets related os.

this retrieved guest intrinsic exchange items.

# filter parsing xml data filter import-cimxml  {     # create new xml object input    $cimxml = [xml]$_     $cimobj = new-object -typename system.object      # iterate on data , pull out value name , data 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 hyper-v server use $hypervserver = read-host "specify hyper-v server use (enter '.' local computer)"  # prompt virtual machine use $vmname = read-host "specify name of virtual machine"  # virtual machine object $query = "select * msvm_computersystem elementname='" + $vmname + "'" $vm = gwmi -namespace root\virtualization\v2 -query $query -computername $hypervserver  # kvp object $query = "associators of {$vm} 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 results try {     $kvp.guestintrinsicexchangeitems | import-cimxml | name -eq "osname" } catch {     write-host "not found" } 

from ben armstrong’s virtualization blog.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -