Solved

Hyper-V 2012 WMI VBS

Posted on 2014-01-13
2
735 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…

770 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