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
Solved

Hyper-V 2012 WMI VBS

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Why should I virtualize?  It’s a question that’s asked often enough.  My response is usually “Why SHOULDN’T you virtualize?”
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

840 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