Printing a VI server’s inventory
Posted by: Akutz
Here is a quick Perl script I wrote to print out your VI server’s (VC or ESX) inventory. I know what you’re thinking, “Um, aren’t there already examples that do this?” Yes and no. See, most examples you find, including VMware’s own, will print out all the VMs or the VI hierarchy as defined by the SDK. My script prints out the inventory based on the hierarchy that is displayed in the VI client. Here is some example output:
[0]akutz@amends:$ printinventory.pl --server vcms.lostcreations.com --username akutz --password mypassword
[Folder] foo
[Datacenter] foo_dc
[Datacenter] austin
[ClusterComputeResource] garage
[ResourcePool] coldair
[ResourcePool] hotair
[ResourcePool] rp2
[VirtualMachine] purple.lostcreations.local1
[ResourcePool] wheel
[ResourcePool] rp3
[ResourcePool] rp4
[HostSystem] mandy.lostcreations.local
[HostSystem] morning.lostcreations.local
The printinventory script, and others, can be found on my web site or you can browse directly to the printinventory code view.
Why should the inventory you see be any different that what the VI client shows you? Sometimes it is helpful to be able to produce the same output as another program. Especially if you’re attempting to mimic that program’s functionality. Coming up, ivi.




