Solved

Hyper-V 2012 WMI VBS

Posted on 2014-01-13
2
717 Views
Last Modified: 2014-11-12
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 ResourceAllocationSettingData.Connection(0).

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

Open in new window

0
Comment
Question by:javelinict
  • 2
2 Comments
 

Accepted Solution

by:
javelinict earned 0 total points
Comment Utility
Problem solved! after restarting the server
0
 

Author Closing Comment

by:javelinict
Comment Utility
problem solved after restart
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Using the Hyper-V Manager requires administrator rights. This guide shows how to add shortcuts and Start Screen tiles for normal users to quickly connect to local virtual machines rather than using the recommended Remote Desktop connection.
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now