Using Powercli to Create a Virtual Machine Report

In doing consulting work there are a lot of times I am asked for a report on this or that. One of the most common things I am asked for is a Virtual Machine report. When this task come up I have two go to scripts. One gets me all the info I want on the VM's and exports to a CSV. The second is used when I have to give the client a nice clean report. For this second script I leverage a powershell module called PScribo. It is downloadable from the PowerShell Gallery or from powershell itself. Use this command to install PScribo. Install-Module PScribo.

In this post we will walk through both scripts then at the end I will leave links to download and use these if you would like. Let's get started.

The first script is a fairly simple one. It asks for the vCenter info then prompts you to login. The next part I added some code to gather the vmtools information and status. The rest is long one liner. I added some extra stuff. I like to see the IP address, and in some cases the VM name and FQDN are not the same. For this, I added a field to get that FQDN. The rest of the info I gather is already a part of the Get-VM command. Below is a snip of the code of the script.

Also here is a sample of the CSV headers.

That's pretty much it for the first script. Pretty quick and easy to get all the info needed from the Virtual Machines. On to the second script.

There are not a whole lot of differences in the two scripts other than the PScribo module. If you haven't used this module yet I highly encourage you too. This module brings a whole new way to present data from Powershell. I leverage the Cover sheet and table of contents for this script but they are optional if you don't want to use them. I use this script mainly when I want to provide something other than a CSV to a client or management. Here in this script we will output into Word and HTML documents. Lets walk through this one.

The first part of the script we will make sure that PScribo is installed then ask some questions to get our variables.

The next section of the script is where all the PScribo styles are defined.

The rest of the script will look similar to the other one except for the style that PScribo needs.

Here are some examples of the Report that this one creates. I am using pieces of the HTML report.

Here are the links to the scripts;



Hope you find this one useful. Thanks for reading!