VMware {code} Community
RUG201110141
Enthusiast
Enthusiast

perl script for identifying what machines are on what ESX hosts

Has anybody created a perl script that can connect to virtualcenter and return information on what virtual machines reside on what ESX servers? I have a monitoring suite that I would like to use something like this in for collection of information for our operations center.

Reply
0 Kudos
3 Replies
StefanPahrmann

Hi,

replace the first 3 lines with the appropriate values.

my $service_url="https://localhost/sdk";
my $username="";
my $password="";

use VMware::VIM2Runtime;
use VMware::VILib;

Vim::login(service_url => $service_url, user_name => $username, password => $password);
my $host_views = Vim::find_entity_views(view_type => 'HostSystem');
foreach (@$host_views) {
    print "Host: ".$_->name."\n";
    my $xvm_views = Vim::find_entity_views(view_type => "VirtualMachine",
                                     begin_entity => $_ );
    foreach(@$xvm_views){

        print "   VM: ".$_->name."\n";
    }
}

Vim::logout();

Regards

Stefan

Reply
0 Kudos
RUG201110141
Enthusiast
Enthusiast

So by the first three lines I presume you mean add my specifics for the three variables $service_url, $username, and $password. I've done that and I run the script from my Windows machine that has the VMware VI Remote cli and I get the following. Obviously I'm not the most the most capable person with perl. Appreciate the help.

C:\perl_scripts>virtualmachine.pl

Can't locate VMware/VIM2Runtime.pm in @INC (@INC contains: C:/Program Files/VMwa

re/VMware VI Remote CLI/Perl/site/lib C:/Program Files/VMware/VMware VI Remote C

LI/Perl/lib .) at C:\perl_scripts\virtualmachine.pl line 1.

BEGIN failed--compilation aborted at C:\perl_scripts\virtualmachine.pl line 1.

Reply
0 Kudos
StefanPahrmann

Have you installed the viperltoolkit? And rebooted the server after that? Seems that the PATH-variable wasn't set yet.

Regards

Stefan

Reply
0 Kudos