Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Hyper-V 2012 WMI VBS

Posted on 2014-01-13
2
Medium Priority
?
782 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

Why should I virtualize?  It’s a question that’s asked often enough.  My response is usually “Why SHOULDN’T you virtualize?”
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

730 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