Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 224018

Getting a count of all VMs (with some filtering)

$
0
0

I'm trying to get a total count of VMs, excluding some vShield Edge devices and any VMs in a certain Resource Pool (System vDC). I'm starting with this:

 

use strict;

use warnings;

use VMware::VIRuntime;

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

 

Opts::parse();

Opts::validate();

Util::connect();

use Data::Dumper;

 

# Obtain all inventory objects of the specified type

my $e_vm = Vim::find_entity_views(view_type => 'VirtualMachine',properties => ['summary.config.name']);

my $count = 0;

foreach (@$e_vm) {

        my $vmName = $_->{'summary.config.name'};

        if (!($vmName =~ m/EdgeGW/i) && !($vmName =~ m/^vse/i)){

                $count++;

        } else {

                print "Checking... VMName: ".$vmName."\n";

        }

}

printf("TotalVMs:%d \n",$count);

Util::disconnect();

 

That works pretty well, but trying to go to the next step is where I'm having troubles. In theory, there should be a resourceConfig.entity.name string (if I'm reading the API documentation correctly). I can't seem to figure out how to obtain that string for comparison inside the foreach loop.

 

Any ideas?


Viewing all articles
Browse latest Browse all 224018

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>