For a project we are doing, we needed a script that gets a list of all virtual machines belonging to a specific datacenter object. At first we tried to do it in .NET with C#. However, because of the complexity of the object model, we quickly had to turn to something else.
The VI3 Perl Toolkit turned out to be much, much simpler. After installing ActivePerl on Windows, we installed the toolkit following the instructions on the website. According to the instructions, you have to use ppm (Perl Package Manager) to download some additional packages that the VI3 Perl Toolkit needs. If you use a proxy server, first set an environment variable with proxy settings before you run ppm. For example:
set http_proxy=http://username:password@proxyserver:proxyport
The VI3 Perl Toolkit contains a guide in HTML format and some samples to get you started. From that guide, we quickly made the script we needed. It looks something like this:
use strict;
use warnings;
use VMware::VIRuntime;
Vim::login(service_url => https://virtualcenter/sdk/vimService, user_name => "user", password => "password");
my $dc = Vim::find_entity_view(view_type => "Datacenter", filter => {'name' => 'datacentername'} );
my $vms = Vim::find_entity_views(view_type => "VirtualMachine", begin_entity => $dc);
foreach (@$vms) {
print "Name: " . $_->name . "\n"
}
I think the code is pretty self-explanatory and very simple, even if you don't know Perl. Vim::login connects to the VirtualCenter web service using https. Then, a reference to the datacenter is retrieved (find_entity_view) and saved in the $dc variable. After that, all the virtual machines in that datacenter are retrieved (find_entity_views) and printed on screen.
One thing to note is that the toolkit does not have issues with non-trusted certificates. We use these default certifates in our test environment.
If you are not a developer and you need some quick scripts to do stuff with VI3, I recommend you use the VI3 Perlkit instead of trying it with .NET.
(Quick note to VMware: you should make it simpler to script VI3 using Windows tools in a supported way. It should be easy to access VI3 using mainstream tools that Windows administrators are accustomed to. With that I mean tools such as COM and VBScript. Or make simpler .NET classes so that we can use them easily in Visual Studio or even PowerShell.)



