I got a request asking for "is there a way to find out the VM’s that are configured on each Hyper-V server ,if so ,how to I generate a report with its Base/Host Name and its VMS running on it with its possible VM setting info ".
hmm..Getting VM’s that are running on Hyper-V and its VM properties ? okay,if the VMs are running on hyper-V ,then these should be registered in WMI Name space .
I then Started digging to find some information about Hyper-V and its stored location in WMI .
Couple of blogs that I come across during my search.
and http://msdn.microsoft.com/en-us/library/hh850319(v=vs.85)
https://blueprints.launchpad.net/neutron/+spec/hyper-v-wmi-v2
From the above blogs,I captured some important information which will be be helpful:
if you are running VMS on Windows 8 or server 2012,the name space for the VM’s located is called V2 Name Space (root\virtualization\v2),to know more about why V2,read this blog .
If you are running VMs on server 2003 or server 2008, the Name Space for the VM’s located is called V1 (root\virtualization).
In short: OS <= 2008 R2: V1 (root\virtualization) , OS >= 2012: V2 ( ).
This request can be achieved using Configuration manager 2012 and I think its not that difficult for someone who already experienced with importing /Adding Custom MOF properties into Hardware inventory settings.
Before I jump into the configuration part ,I need to get/verify what information is stored in WMI name space for the VM’s. Refer this blog to know attribute values from Msvm_ComputerSystem class.
From the existing values,I choose to get important values like Elementname,Caption,Enabledstate,Installdate,Enabledefault,TimeOfLastStateChange,TimeOfLastConfigurationChange.
Run the below powershell query ,to see its values for each VM:
gwmi -namespace "root\virtualization\v2" MSVM_ComputerSystem |select elementname,caption,
enabledstate,installdate,enabledefault,TimeOfLastStateChange,TimeOfLastConfigurationChange |Out-GridView
I get something like below on my windows 8.1 machine:
we have now identified what values we want to be present in SQL/SSRS Report.
Having this information in place,one would think ,we can get this information by enabling the custom inventory class from root\virtualization\v2 Msvm_ComputerSystem but if you configure this way ,client will fail to retrieve the information from WMI and you end up with following error from inventoryagent.log
error msg: Unknown error encountered processing an instance of class Msvm_ComputerSystem: 80041001
As per the configurations from client device settings,it is trying to run query SELECT __CLASS, __PATH, __RELPATH, CreationClassName, Name, ElementName, EnabledState, InstallDate, TimeOfLastConfigurationChange, TimeOfLastStateChange FROM Msvm_ComputerSystem against namespace root\virtualization\v2 and is failing to do so.
Thanks to Mof Moster (Sherry Kissinger) for providing the solution to make this working.
Solution :
In order to get the VM info Into CM Database,we need to create custom name space in WMI (cm_msvmcomputersystem) ,Pipe the vm info from Msvm_ComputerSystem and then try import that info CM DB using MOF file.
This setup requires you to create Configuration Items ,import the MOF file into Client Device Settings and Run report.
Note :This solution will work for hyper-V running server 2008/R2,windows 8/8.1,server 2012/R2 with namespace root\virtualization or root\virtualization\v2.
If you have any other namespace that store the VM’s ,you may need to edit the Powershell Script in CI,also the MOF file.
Download the Attached CI Cab file,MOF file and SQL Report with instructions from here
on your client ,refresh the machine policy,you would see ,the CI as compliant.
check if the namespace (cm_msvmcomputersystem) created in WMI or not ?
Run the Inventory action ,should see something like below :
wait for a while before site server process this information.
SQL Report:
Hope It Helps!
6 Comments
Any thoughts on why the HyperVGuest would be NULL?
can you provide more information on what are you trying to do ?
Thanks,
Eswar
It turns out in 1606 there is another table/view named v_GS_VIRTUAL_MACHINE_64. As the name implies it contains the 64-bit machines.
but it doesn't tell you how many vms are running on hyper-v and my post is talking more about how to get the number of VMS running on the host.
regards,
eswar
Great post. Do you by chance know how to do the same for vSphere?
I dont have vsphere to test.. Is that running on vsphere? Does it have wmi? Can that be managed via Configmgr?