javelinict
asked on
Hyper-V 2012 WMI VBS
Hi all,
In Hyper-V 2008 R2 I used the following code to check for VHDX files (snapshots). This doesn't work anymore in Hyper-V 2012 R2.
I've noticed the WMI service changed to \\.\root\virtualization\v2
Thing work fine then except for the Resource type 'Microsoft Virtual Hard Disk' doesnt exists anymore. It's a 'Synthetic' harddrive now. When I change the code to reflect to the new
name I cannot get an object anymore from ResourceAllocationSettingD ata.Connec tion(0).
Can anyone help me to get this script working in 2012 R2?
With regards,
Robbert
In Hyper-V 2008 R2 I used the following code to check for VHDX files (snapshots). This doesn't work anymore in Hyper-V 2012 R2.
I've noticed the WMI service changed to \\.\root\virtualization\v2
Thing work fine then except for the Resource type 'Microsoft Virtual Hard Disk' doesnt exists anymore. It's a 'Synthetic' harddrive now. When I change the code to reflect to the new
name I cannot get an object anymore from ResourceAllocationSettingD
Can anyone help me to get this script working in 2012 R2?
With regards,
Robbert
Set objWMIService = GetObject("winmgmts:\\.\root\virtualization")
result = ""
teller=0
Query = "select * from Msvm_ComputerSystem where caption='Virtual Machine'"
Set GetComputersystem = objWMIService.ExecQuery(Query)
For Each obj In GetComputersystem
Query = "Associators of {" & obj.path_.Path & "} Where ResultClass=Msvm_VirtualSystemSettingData AssocClass=Msvm_SettingsDefineState"
Set VMSettingDatas = objWMIService.ExecQuery(Query)
For Each VMSettingData In VMSettingDatas
Query = "Associators of {" & VMSettingData.path_.Path & "} Where ResultClass=Msvm_ResourceAllocationSettingData AssocClass=Msvm_VirtualSystemSettingDataComponent"
Set ResourceAllocationSettingDatas = objWMIService.ExecQuery(Query)
For Each ResourceAllocationSettingData In ResourceAllocationSettingDatas
If ResourceAllocationSettingData.ResourceSubType = "Microsoft Virtual Hard Disk" Then
vhdpath = ResourceAllocationSettingData.Connection(0)
If InStr(1, vhdpath, ".avhd") Then
Debug.Print "Virtual Machine : " & obj.ElementName & " has an active snapshot"
End If
End If
Next
Next
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER