Multiple MSVM classes query

Hi

I am trying to get a value for a virtual machines disk drives to see if they are dynamic or static. I have worked out that I need to be looking for MSVM_VirtualHardDiskInfo = 3 for dynamic and 2 for static. I have worked out so far how to get the vm to pass its hyper-v host that it is on and connect by element name but can't work out how to add the extra command for the MSVM_VirtualHardDiskInfo. I just want the number 2 or 3 passed back. Here is what I have

$vguest = $env:COMPUTERNAME

$vhost = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").Hostname


$vms = Get-WMIObject -Class Msvm_ComputerSystem -Namespace "root\virtualization" -ComputerName $vhost| where-object {$_.elementname -eq $vguest}

Thanks

J

March 26th, 2014 2:28pm

You might want to ask this in the Virtual Server forum:

http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?category=virtualserver

I don't have access to be able to play around to test.  MSVM_VirtualHardDiskInfo is embedded in the MSVM_ImageManagementService class and can be invoked with the GetVirtualHardDiskInfo() method, and access the Type property that method returns.  You'd need the path to the virtual hard disk associated with that virtual machine, and that's where I'm running into a brick wall trying to help by using WMI.  

http://msdn.microsoft.com/en-us/library/cc136845(v=vs.85).aspx

Since you're using WMI instead of Poweshell cmdlets, the Virtual Server forum would probably get you an answer quicker.

Using Powershell cmdlets, you might be able to do something like this:

$vhd = invoke-command -computername $vhost -scriptblock {
   param($vguest)(Get-VMHardDiskDrive $vguest).path | %{
      (Get-WMIObject -Class Msvm_ImageManagementService -Namespace "root\virtualization").GetVirtualHardDiskInfo($_).Type
} } -ArgumentList $vguest

I have not tested this at all so no idea if it will work.

Free Windows Admin Tool Kit Click here and download it now
March 26th, 2014 3:46pm

Thanks Rhys I will have a play with your suggestions and get back to you :)
March 27th, 2014 8:27am

Hi Rhys

I got it to work! Perhaps not in the cleanest fashion but it works (I am trying to use SCCM compliance checks hence the pass of fail)

invoke-command -computername vmmserver -scriptblock {

Add-PSSnapin microsoft.systemcenter.virtualmachinemanager

$vguest = $env:COMPUTERNAME

(get-vm -vmmserver vmmserver $vguest).virtualharddisks | ForEach-Object {if ($_.VHDType -eq "DynamicallyExpanding") {write-host "Fail"}

else

{write-host "Pass"}


}

}

Free Windows Admin Tool Kit Click here and download it now
March 27th, 2014 12:57pm

Glad you got it to work!
March 27th, 2014 1:37pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics