Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hyper-V 2012 WMI VBS

Posted on 2014-01-13
2
Medium Priority
?
798 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
ID: 39899851
Problem solved! after restarting the server
0
 

Author Closing Comment

by:javelinict
ID: 39899852
problem solved after restart
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange users below are the steps you can follow to upgrade your Lync server to latest CU's or cumulative updates. Note: Perform it during non-production hours.   Step 1: Backup your lync and SQL server database. Follow below article: h…
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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). …
Suggested Courses

824 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