Working at large scale with thousands of servers customers often asks for a list of machines with various properties for each machine.
Most of the time the customer want this information in an simple format (read CSV, the World isn’t as advanced as you like!) so that they can use it internally. In this blogpost I will show how you can get the information about memory, CPU count etc for a set of Hyper-V machines from Virtual Machine Manager via PowerShell.
Start a PowerShell command line and load the PowerShell Snap-In for Virtual Machine Manager.
Now we can work with the commands made available to us by the Snap-In, if you want to find all the commands that are available issue:
So let’s begin by loading information about all our machines from the VMM host into a variable named $VMs
What the above command does is to load all of the VMs on the host HYPER-V-01.mydomain.com into the variable $VMs. This means we will only do one call to the server which avoid generating unnecessary load.
Now let’s check how many machines we have:
And now that we know we have machines to query, let’s find out what attributes exists (things we can get into our output)
For example, to find all macines that are powered off:
The above example adds some complexity to the command, but it is to filter so we only see machines that have the status is ‘PowerOff’.
Now let’s get what we wanted from the beginning, a list of machines for a specific customer. The list should include name of the VM host, VM name, memory, number of CPUs and current status.
This will list all machines who’s name begins with ‘CUST’. So we now have found what we wanted!
But instead of copying & pasting this we want to write the result to a CSV file so we can send that to the customer. Let’s make that easier by getting the output of the above command into a variable named $result
Now our ‘report’ is stored in the $result variable and we can use standard PowerShell to export it to a CSV file:
Now our report is available in a CSV file on the file ‘report.csv’ (in the current directory)
A very basic way of getting your Hyper-V inventory out!