Archive for abril \13\UTC 2009|Monthly archive page

List All VMs

Fonte: http://communities.vmware.com/blogs/froboy
Ps: precisa ter o VMware VI Remote CLI instalado.

#!/usr/bin/perl -w
#
# Copyright 2006 VMware, Inc.  All rights reserved.
#
# This script prints names of all VM’s with Windows guest
# listallvms.pl –server <VC Server> –username <username> –password <password>

use strict;
use warnings;

use VMware::VIRuntime;

# read/validate options and connect to the server
Opts::parse();
Opts::validate();
Util::connect();

# find datacenter
my $intype;
$intype = “Datacenter”;

my $datacenter_views = Vim::find_entity_views(view_type => ‘Datacenter’);

my $counter = 0;
print “DataCenters found:\n”;
foreach (@$datacenter_views) {
print “Datacenter: ” . $_->name . “\n”;
$counter++;

my @vms;
my $vmcount = 0;

print “\n –VMs found:\n”;
# get all VM’s under this datacenter
my $vm_views = Vim::find_entity_views(view_type => ‘VirtualMachine’, begin_entity => $_);
foreach (@$vm_views) {
my $vm_name = $_->name;

push (@vms, $vm_name);
}

@vms = sort {lc $a cmp lc $b} @vms;

foreach my $vm_name (@vms) {
print ” — VM: $vm_name\n”;
$vmcount++;
}
print ” — Total VMs: $vmcount\n”;

}

print “Total Datacenters: $counter\n”;

# disconnect from the server
Util::disconnect();

Anúncios