New PowerShell VM Inventory Script for SCVMM 2012 SP1/R2

about 1 1/2 years ago I made a script for Inventory Reporting in SCVMM 2012 and now I have been working on an update that supports VMM 2012 Sp1 and R2, there have been some changes in the cmdlets so now it was time to refresh it and add some information.

In VMM 2012 R2 the possibility to get the IP address has been added so I utilize that from VMM, if you are using the SP1 version I can get the IP address from the Hyper-V PowerShell module and the cmdlet Get-VMNetworkadapter, that works only on Hyper-V 2012 Hosts and the Integration components have to be updated. The function reports the number of NIC´s and VHD´s but not show all, I have chosen to just add one virtual NIC and three virtual hard disks in this, that can be altered if you want and just add in the hash table.

In this new function I have added a switch parameter that lets you select if you want a html/csv report or just work with the objects that comes out of it when running 🙂

To use it you can just use one of several ways with parameters

Screen Shot 2013-09-29 at 22.38.05


And here is the script function

And here is an example of the csv report, and yes it is much info, the CSV can be scrolled quite a bit 🙂

Screen Shot 2013-09-29 at 22.27.45

You can select what you want included in the report by just using the function and pipe it to Export-CSV





I do not have SCVMM installed..

Can this script be converted for use with PowerCLI?


Thank you Niklas for all the job done on this script.
I test it yerterday and I didn’t manage to get output.
I work with SCVMM2012 R2 and I launch the script from SCVMM PS in “C:\sources\scripts\”, running an account with SCVMM admin rights.
The script just return to prompt after only 1 second and I have no result, no VMdata.* file.
Is there something more to be done ?
Thanks a lot !!


Hi Niklas

I have the same problem as frouxel. Im trying to run the script in SCVMM2012 SP1 but nothing returns back



Im running it on scvmm 2012 R2 and nothing returns when running the script. Please assist.

Chris Addison

Hi Niklas

We have SCVMM 2012R2 and all our hosts are 2012R2 as well. l have the same symptoms as frouxel, Dennis and Naomi. This would be a very handy script to get running. I’m sure we must be doing something silly, but I’ve tried everything.

Any clues you can provide?


I will check this as soon as I get some time 🙂


Hello everyone,

After stepping thru this I found three items that I hope will help everyone:

1) I had to change line 36 version to match my version of SCVMM (I ran “get-scvmmserver localhost | fl ProductVersion” to get my version)

2) Line 33 may attempt to load Module Hyper-V, which is used in the ‘if’ statement on line 65 if you are not running R2. I just commented this line out since I know I am using R2+

3) Probably the most important and addresses some comments here —

The script creates a Function, but never calls the Function. This could just be that I don’t know how to properly use it. If I run the script in Powershell and then try to run the function “Get-SCVMInventory”, I receive an error stating that Get-SCVMInventory is not a valid cmdlet, function, etc.

The interesting part is that if I run the script in Powershell ISE and then run the function it successfully runs.

Because I like things simple and don’t want to have to remember to use ISE when using this script, I have just replaced line 155 with my desired command, such as “Get-SCVMInventory -report”. I’ll just make a couple copies for the commands I use frequently.


I spent a few minutes looking up using Function in PS and found out how to use this as intended.

In the directory containing the script enter the following command (note that there is a space between the two periods:
“. .\Get-SCVMInventory.ps1”

This should have registered the Function. To confirm enter the following command:
“ls function:\”

This should list available Function and “Get-SCVMInventory” should now be present in the list and can be used in this Powershell session/window. It won’t be available in other sessions/windows.


This is not working, please help

Abhishek Shivhare


I am looking for power shell script for Hyper-V VM’s inventory. My SCVMM server got crashed, so I have only option to take the inventory from one of the host. Can you help here?

Maurice Brown

I must be doing something wrong due that i still get nothing running this script


hi, I tried this and the script is still doing nothing. Nikals any updates ?

Thank you

Josip Ivkovic

Hi everyone,

Here are the steps for running this script and getting the reports:

1. Start “Virtual Machine Manager Command Shell” (with “Run as Administrator”)

2. Navigate to the folder where you copied the .ps1 file

3. Enter the following command:
. .\Get-SCVMInventory.ps1

4. For creating a report for a Hyper-V cluster enter the following command:
Get-VMHostCluster ClusterName | Get-SCVMInventory -report


hi all
I did the following
1. Start “Virtual Machine Manager Command Shell” (with “Run as Administrator”)

2. Navigate to the folder where you copied the .ps1 file

3. Enter the following command:
. .\Get-SCVMInventory.ps1

4. For creating a report for a Hyper-V cluster enter the following command:
Get-VMHostCluster ClusterName | Get-SCVMInventory -report

every time i’m running I get

“Get-SCVMInventory : The term ‘Get-SCVMInventory’ is not recognized as the name”

please advice?


Thank you, the script works great,
solves alot of unknowns for me 🙂


Great Script. Thx.
I had some issues with line 46. The command ‘Get-SCVMHostGroup’ is not performing well
$VMHosts = (Get-SCVMHostGroup -Name $VMhostGroup).AllChildHosts
$VMHosts = Get-SCVMHost


Works like a charm. Thanks!

Just execute with param: “-report”
“Get-SCVMInventory -report”


You need to run the Get-SCVMInventory after you run the script..



I have an issue with the VHD´s, I only get 3 in the report but we have up to 15 VHD´s the Count works. I have tried adding this to the script without success.

VHDName4 = $VHDConf[3].Name
VHDFormatType4 = $VHDconf[3].VHDFormatType
VHDSize4 = $VHDconf[3].MaximumSize/1GB -as [int]
VHDCurrentSize4 = $VHDconf[3].Size/1GB -as [int]
VHDBusType4 = $driveConf[3].BusType
VHDBus4 = $driveConf[3].Bus
VHDLUN4 = $DriveConf[3].Lun
VHDDatastore4 = $VHDconf[3].Directory


Thank you for this excellent script.


Thanks, nice article.. one question, how do i add different attributes to the report. For example how can i add (in the vmm machine custom properties owner & unit fields).



just add the relevant custom property around line 96 in following form:
Environment = $VM.CustomProperty[‘Env’]
This is for a custom property named Env, but will also work for Custom1, etc

Leave a comment


email* (not published)