Cant query VM's file using root\virtualization WMI namespace in Windows 2012 R2


i using following script list of disks attached vm.

$hypervparent = "localhost" 
$hypervguest = "testvm" 

$vmmanagementservice = get-wmiobject -class "msvm_virtualsystemmanagementservice" -namespace "root\virtualization"
$vm = get-wmiobject -namespace "root\virtualization\v2" -computername $hypervparent -query "select * msvm_computersystem elementname='$hypervguest'" 
$vmsettingdata = get-wmiobject -namespace "root\virtualization\v2" -query "associators of {$vm} resultclass=msvm_virtualsystemsettingdata assocclass=msvm_settingsdefinestate" -computername $hypervparent 


#getting path's attached vhd's 
$virtualdiskresource = get-wmiobject -namespace "root\virtualization" -query "associators of {$vmsettingdata} resultclass=msvm_resourceallocationsettingdata assocclass=msvm_virtualsystemsettingdatacomponent"
-computername $hypervparent | where-object { $_.resourcesubtype -match "microsoft virtual hard disk" } 
     
foreach-object -inputobject $virtualdiskresource -process { 
    write-host "virtual hard disk at: $_.connection[0]" 



#getting disk attachments passthrough disks 
$physicaldiskresource = get-wmiobject -namespace "root\virtualization" ` 
    -query "associators of {$vmsettingdata} resultclass=msvm_resourceallocationsettingdata assocclass=msvm_virtualsystemsettingdatacomponent" ` 
    -computername $hypervparent | where-object { $_.resourcesubtype -match "microsoft physical disk drive" } 
     
foreach-object -inputobject $physicaldiskresource -process { 
    write-host "passthrough disk at: " ([wmi]$_.hostresource[0]).elementname 
    write-host "passthrough disk drive number: " ([wmi]$_.hostresource[0]).drivenumber 
}

same query not work on windows 2012 r2. 

aparently root\virtualization namespace deprecated windows 2012 r2. did observed same?

r2 not released preview status yet, no statements made in regards until then.

you should concern v2 virtualization namespace (this began 2012).  , v1 namespace existed backward compatibility.

at time, can discover.


brian ehlert
http://itproctology.blogspot.com
learn. apply. repeat.
disclaimer: attempting change of own free will.



Windows Server  >  Hyper-V



Comments

Popular posts from this blog

Generating Event ID 91, 44 with CA (In Event Viewer with source as Certsvc)

Group policy default policy cannot be edited because network name not found

Problem when changing update source