During one of my engagements as a Professional Services Consultant I needed to upgrade a vSphere 5.1 environment to vSphere 6.

Detailed steps for this exercise are found on my wiki because I believe this can be better documented in wiki format.

Not really exciting when you have enough hosts available to play with.
But one of the things that I stumbled into is that I wanted to have a list of all the VM’s that are hosted within the vSphere environment.

One of the ways to do this is to browse trough the web-client and select the Data Center  (or vCenter Server) object and look / export / copy-paste the VM’s from the related objects VM tab.

As being a CLI guy for a few years I expected that the vCenter Server or the ESX hosts had this functionality build in… well I was wrong.
So after using Google over and over again I discovered that I needed to do this either trough Python or trough Power-shell.

In this post I am going to explain you the Python way. This is really going to a “beginners” guide as I needed to start from the beginning as well.

Below you will find the steps that I had to take (as an absolute vSphere + python beginner) to gather a list of VM’s with python.

  1. Install OSX on a separate VM (using Fusion)Install OSX on a separate VM (using Fusion)
  2. Verify the default python version that came with Yosemite
  3. Install pip
  4. Use pip to install pyvmomi
  5. Verify version pyvmomi
  6. Get pyvmomi repo from github
  7. Create a new user in vCenter to make python calls to vCenter Server
  8. Execute one of the sample Python scripts in the sample directory (getallvms.py)
  9. Alter the getallvms.py script to only show virtual machine names
  10. Execute getallvms.py again
  11. Try another script that provides information about VM’s ((py-vminfo.py)
  12. As a bonus another script to test with (vminfo_quick.py)

Detailed steps for this exercise are found on my wiki because I believe this can be better documented in wiki format.