Powered by System Center
Collecting Data from Hyper-V hosts and VM’s
There haven’t been any new blogs on Hyper-V.nu in the past weeks because of …. you know … an absolute dearth of time. It so happened that my other Hyper-V.nu colleagues had the same luxury problem in these economical challenging times.
So while I was doing a lot of other things which I will soon be able to talk about, I asked my colleague Sander Klaassen to fill in the gap and write a guest blog. Sander is also a Microsoft virtualization enthusiast and combines this with his broad other expertise.
Please welcome our guest blogger Sander Klaassen!
____________________________________________________________________________________________________________________________________________
Over de last years I developed a script to quickly scan a customer’s IT environment. Recently I added a Hyper-V module which collects data from Hyper-V hosts and VM’s. I showed Hans Vredevoort the output and he asked me to write a blog about it. I was not sure to share the code, because it isn’t very clean, since I only occasionally work on it.
I created a VBScript and not a PowerShell script because I wanted to be able to run it without installing anything, and VBScript is part of windows since Windows 2000 so it’s always available.
This is also the reason why I made this script besides the regular Microsoft scan tools like ACT and MAP. They all need installation of components or even agents.
I modified the script for this blog, I changed the script by requesting input in a text file instead of Active Directory. This text file is a simple list of machine names:
-
HyperV01
-
HyperV02
-
HyperV03
Save it in the same directory as the VBScript with the name “machinelist.txt”
The script queries WMI name spaces of each machine and when it finds the Hyper-V role, it collects the following information:
The VMMemDemand value was particular challenging; I couldn’t find the value anywhere in WMI, so I asked Hans if he knew, he forwarded the question to his fellow MVP’s and he got an answer. No wonder it was difficult to find. Turned out it is calculated from 2 values in a WMI property that contains an array filled with XML blobs.
The script makes a CSV output file in the directory of the script, using semicolon (;) as the separator character. This script should be run with elevated rights. (Otherwise, the cluster information is not complete)
The output is optimized for pivot table use in Excel. So with pivot tables the collected information can be formed to actually say something.
JSNVI01 and JSNVI02 are two hyper-V hosts in a cluster, each with 8 physical cores. First node has 8 virtual cores while the second node has 15 virtual cores active. Same goes for memory.
With a slightly more complex pivot table you can find SP1 VM’s with a lower memory demand then the VMMemMin value.
This means the VM uses less memory then the minimal configured amount, so the minimal memory value can be lowered to save some more memory.
I still have plenty idea’s to add or change the script like getting more VM configuration information while the VM is switched off.
Download script SummarizeHyperV
You can execute this script by the following command:
cscript.exe .\SummarizeHyperV.vbs
Don’t forget to create the textfile with your own Hyper-V hosts in it!
| Print article | This entry was posted by Hans Vredevoort on October 20, 2011 at 21:49, and is filed under Hans Vredevoort, Hyper-v. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |










Twitter
RSS
about 1 year ago
First, thank you for a neat script.
It seems like your script suceccfully connects to the first node (specified in the machinelist.txt file), the second node reports “CouldNotConnectToWMI” and the third node is not even mentioned in the output CSV.
Thankful for all help.
Regards,
Dan
about 1 year ago
Hello!
Could be 3 causes;
1) You don’t have rights to access WMI on that hyperV host.
2) you cant connect to WMI because its blocked by firewall.
3) WMI is corrupt. (not very likely)
regards,
Sander
about 1 year ago
Hi,
I’ve tried your vbs script.
Machinelist is in the same folder with hyperv hosts names.
Excel WorkSheet is created but with no data (except row header).
I’ve put a wrong Hostname to test.
No ping reply is present in excel.
But for other hosts, nothing.
Is there something to verify ?
My hosts are French W2008 R2 Sp1.
Regards
about 1 year ago
Thanks for your comment. I sent your question to the author.
From what machine do you run the script?
I can confirm this script works with English localization. Perhaps you can temporarily change it on the machine you are running the script.
Regards, Hans
about 1 year ago
thanks for trying the script!
I think the cause of why the script doesnt work is because part of wmi contents is translated to french.
My first guess would be “Hosting Computer System” is translated to French.
If you run the following cmdline on a hyper V host:
wmic /namespace:\\root\virtualization PATH Msvm_ComputerSystem GET Caption
It should show “Caption” on the first line. On the second line, the french equivalent to “Hosting Computer System” and the rest french words for “virtual machine”
If you replace “Hosting Computer System” and “virtual machine” in the script with the french equivalents. It should work. unless they decided to translate alot more.
Please share the outcome!
about 1 year ago
Hi,
cmdline return :
Caption
Système informatique d’hébergement
Ordinateur virtuel
I’ve modified the script but unfortunaltely it’s not better.
Maybe accent are not well understanded ?
about 1 year ago
The accents could be the problem, but im not sure.
I dont see them on an English server.
You could troubleshoot it by inserting a messagebox popup on line 60:
wscript.echo objHPVHost.Name
then you know if the script accepts the french translation “Système informatique d’hébergement
“.
same goes for the virtual machine equivalent.
Or you could use an english server ;]
good luck!
Sander