While creating and converting VM’s using SCVMM puts the configuration files and VHD’s in a nicely structured set of folders, if you create a VM through Hyper-V Manager or convert using disk2vhd, the files will be stored based on the GUID for the VM, which isn’t found anywhere in the GUI tools for Hyper-V.
Luckily I came across this blog post to which I owe full credit for the solution:
Save the VBS script below as guid.vbs, copy to your Hyper-V host, and use psexec to execute it with this:
psexec \\hyperv cmd.exe cscript c:\guid.vbs
You are using PSexec right?
Option Explicit Dim WMIService Dim KvpComponents Dim VMList Dim VMSettingList Dim VM Dim item Dim setting Dim component 'Get instance of 'virtualization' WMI service on the local computer Set WMIService = GetObject("winmgmts:\\.\root\virtualization") 'Get all the MSVM_ComputerSystem object Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem") For Each VM In VMList if VM.Caption = "Virtual Machine" then WScript.Echo "========================================" WScript.Echo "VM Name: " & VM.ElementName WScript.Echo "VM GUID: " & VM.Name WScript.Echo "VM State: " & VM.EnabledState ' Now get the BIOS GUID for this VM Set VMSettingList = WMIService.ExecQuery("SELECT * FROM Msvm_VirtualSystemSettingData") For Each setting In VMSettingList Dim tempVMname tempVMName = "Microsoft:" + VM.Name if setting.InstanceID = tempVMName then WScript.Echo "VM BIOS GUID: " & setting.BIOSGUID end if Next end if Next |
We can also get the same info using the following command….
Get-WmiObject -Namespace root\virtualization -class msvm_computersystem | select elementname, operationalstatus, processid, name