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