Posey's Tips & Tricks
A Quicker Way To Create Hyper-V Inventory Reports
Over the past several years, I have developed a number of PowerShell scripts to create Hyper-V virtual machine (VM) inventory reports. I made some of these scripts available to the public and others were written purely for personal use. The one thing that all of these scripts have in common, however, is that they were tedious and time-consuming to create.
If you need to periodically generate Hyper-V inventory reports but do not want the hassle of writing your own custom PowerShell script, there is a shortcut. Microsoft has made available a PowerShell script that creates both plain text and HTML-based Hyper-V inventory reports.
You can download the script here. The download consists of a 319KB .ZIP file. Within this .ZIP file, you will find three PowerShell scripts, a couple of HTML files, a .PNG file and a ReadMe file. The script is meant to be run directly on a Hyper-V host (or host cluster) and requires Windows Server 2012 or higher. Client Hyper-V is also supported on Windows 8 and Windows 10. The script is capable of querying remote hosts, but the machine on which the script is run requires administrative privileges.
In order to run the script, you will need to log into Windows using an account that has administrative privileges. You will also need to open PowerShell with elevated privileges.
One thing that I really like about the Hyper-V inventory script is that you can run it without having to provide a bunch of complicated command line switches (although switches are available for your use). Simply run the Get-HyperVInventory.ps1 script, and PowerShell will prompt you about what type of report you want to create. You can see the available options in Figure 1.
Once you have made your selection, the script will start querying your VMs and will then create an HTML report. You can see an example of such a report in Figure 2.
As you can see in the figure above, the script writes the report to the machine's Documents folder. The top portion of the report provides a bit of information about the report itself, such as when the report was created, by whom and on what machine. From there, the report provides information about the VMs residing on the host. As you can see, this particular host contains 47 VMs. For each VM, the report lists things such as its name, state, status, operating system and whether the VM is highly available.
As previously noted, there are several command line switches that you can use with the script. You don't actually have to use any of these switches, but they can come in handy if you need to automate the report creation process. I'm not going to go through all of the available switches because they are documented in the ReadMe file. However, there are a few switches that I want to mention.
One such switch is the output switch. By default, the script writes reports to your documents folder. However, you can use the output switch to direct the output to an alternate location. For example, you might type:
./Get-HyperVInventory.ps1 -Output "C:\Reports"
The mode switch is also useful. It is used to specify what kind of report the script will create. For instance, you can use the mode switch to specify that you want to inventory a cluster instead of an individual host. To use the mode switch, simply append -mode to the command used to run the script, and then type the name of the mode that you want to use. There are five modes available:
The ReadMe file provides a detailed explanation of what each of these modes is used for.
One last switch that I want to mention is format. By default, the Hyper-V inventory script creates an HTML report, but you can use the format switch to create a text-based report instead. To do so, just enter this command:
./Get-HyperVInventory.ps1 -Format TXT
As you can see, the Hyper-V inventory tool can provide a wealth of information about your Hyper-V VMs. This free tool is an excellent resource for keeping track of the VMs that are running on your hosts.
Brien Posey is a 19-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.