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

 

 

Comments

Hein
Reply

I do not have SCVMM installed..

Can this script be converted for use with PowerCLI?

frouxel
Reply

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 !!

Dennis
Reply

Hi Niklas

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

Thanks.

Naomi
Reply

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

Chris Addison
Reply

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?

Niklas
Reply

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

Tim
Reply

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.

Tim
Reply

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.

Manu
Reply

This is not working, please help

Abhishek Shivhare
Reply

Hi,

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
Reply

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

Ryan
Reply

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

Thank you

Josip Ivkovic
Reply

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

MasterIT
Reply

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?

cms
Reply

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

Rui
Reply

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

Nikolay
Reply

Works like a charm. Thanks!

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

alext
Reply

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

Mattias
Reply

Hi

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

Ian
Reply

Thank you for this excellent script.

Samer
Reply

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).

Leave a comment

name*

email* (not published)

website