VMware Cloud Community
Sureshadmin
Contributor
Contributor
Jump to solution

Need Powershell script for VM inventory

Hi,

Need a powershell script to collect the below given info from virtual center.

vmname | ESX Name | memory(GB) | vCPU count | vNIC Count | IP address(all) | vmdk(s) size(GB) | Total vmdk size(GB) | Datastore name | Tools version | tools update | shares | reservations(MB) | limit(MB) | snapshot count | Guest OS

vmdk(s) size(GB) ---> Need all vmdk size of the vm seperated by "". EX: for a vm of 3 vmdk's of size 20,20,10GB each the output would be 2020+10

Datastore Name ---> Name of the datastore where VMX is located.

Tools update ---> Need status like old or updated

85 Replies
LucD
Leadership
Leadership
Jump to solution

Do you have a custom field with the name "CreatedBy" in your vSphere environment ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

Hi Luc,

It working after upgrading PowerGuito latest version.

I have one question, Can I get this report in excel format or in comma seperated format ?

Regards

GD

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, on the last line change this

Out-File "C:\VMreport.txt"

into this

Export-Csv "C:\VMreport.csv" -NoTypeInformation

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

Hi Luc,

Thanks a lot, its working. few changes I have seen after taking the report in csv format, script is not able to fetch the Ipaddress and VMdkname , which it was able to get earlier in txt format.

Instead of ipaddress I am getting System.String[] , and for vmdkname I am getting System.Object[[]|http://] , and for vmdkname I am getting System.Object[]

Any clue.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's because those properties are arrays.

The Export-Csv cmdlet doesn't handle arrays very well Smiley Wink

With the Join function of the String object, you can join the array elements together

See attached script.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

Hi,

Ok, I have tired the changes you have said, got below error.

Cannot find an overload for "Join" and the argument count: "1".

At :line:31 char:34

+ $Report.VMDKname = ::Join <<<< (','.$VMDKnames)

GD

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

HI Luc,

VMDkname was not important for me, so I have remvoed it, and script started working, along with the Ipaddress details.

Can I also get the Vlan this vm has ?

Thanks a ton again.


GD

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There was a typo, a dot instead of a comma.

Attached the corrected version with the VLANids.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

Hi Luc,

As excepted its working, One more question, as I am proving a list to find the vm details, there may be some vm's which are not there in the environment, it is giving error for this vm's on the console, can I get this list of the vm's which didn;t found in a seperate file ?

in memeory field I am not getting the data in GB, it is showing me , 3609375, where it should show me 3696 , I am doing the the calculation in excel fie, is it possible do get the data in GB.

Thanks a ton again.

GD

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The attached script creates a separate file with the guests that were not found.

I'm not sure which field you mean for the GB unit.

What is the name of the property ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jingleharish
Contributor
Contributor
Jump to solution

first of all, Thanks a lot for this script...

The datastoreName is displaying "VMware.Vim.VirtualMachineConfigInfoDatastoreUrlPair[]" for all the VM's.

Also it will good if we can add the port group column.

Thanks !!!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There you go.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
elgreco01
Contributor
Contributor
Jump to solution

hi!

i cant get the script to return anything...

here is what i do:

open vi powershell

i do a connect to the vcenter ip

when i run the ./Get-VMInformation-v3.ps1

the report.csv is empty

what do i do wrong?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The script Get-VMInformation-v3.ps1 writes the output to the console, not a .csv file.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
elgreco01
Contributor
Contributor
Jump to solution

im using the Get-VMInformation-v4-1-to-text-3-1-2.ps1

Are there any steps i should do in order to get a report? should i use any switches after the script?

should i do something other in the powershell before running the script?

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

Hi Luc,

After making the changes in this script Get-VMInformation-v4-1-to-text-3-1-2.ps1 to give the output of the not found vm's in some file, script is giving issue, it doesnt; stops, its just says scripting executing, andnever stops.

when I have disabled the above features from the scrpt, it worked as per desire.

Can you please look ?

Regadrs

GD

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That version uses a .txt file that contains the names of the VMs to report on.

If you want to use the script for all your VMs, you have to change thfirst lines.

This

$allLines = @() # Line added
$null | Out-File "C:\vmnotfound.txt"
Get-Content -Path "C:\vmnames.txt" | %{
	Get-VM -Name $_ -ErrorAction SilentlyContinue
	if(!$vm){
		$_ | Out-File "C:\vmnotfound.txt" -Append
	}
} | ForEach-Object {

should be replaced by this

$allLines = @() # Line added
Get-VM | ForEach-Object {

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There was indeed a bug in the script.

I updated the attached script above.

Please try again.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
elgreco01
Contributor
Contributor
Jump to solution

i just want to let you know that now it works!

0 Kudos
elgreco01
Contributor
Contributor
Jump to solution

the script works like a charm!

how can i add in to get also the stats for the "used space" and "provisioned space" ?

0 Kudos