I’ve been getting back to playing with the VMware API and I’ve completely forgotten everything, so I’m starting off simple. Here is a simple script to connect to a host and to list the names of the VMs that are on it:

#!/usr/bin/perl

use Data::Dumper;
require VMware::VIRuntime;
VMware::VIRuntime->import();
1;

# try logging into a node:
my $conn;
my $hyp = 'vhost31'; # you can make this an option to pass in as well.
eval {  
 $conn = Vim->new(service_url=>"https://$hyp/sdk");
 $conn->login(user_name=>'root',password=>'cluster');  # here are some easy root password stuff you need to change.
};
# make sure the connection worked
if($@){
 print "Couldn't connect:  $@\n";
 exit 1;
}
my $entity_views = $conn->find_entity_views(view_type => 'VirtualMachine');
foreach my $ev (@$entity_views){
 print $ev->name . "\n";
}
$conn->logout();

That’s pretty much it.  Notice that I just printed the name.  There are a lot of other things you could print as well on it if you wanted to.  Just do a print Dumper($ev) and you’ll see the possibilities.