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" }
Comments
Post a Comment