VMware {code} Community
tdfeathe
Contributor
Contributor

VMID

I am trying to get the VMID using the perl API. Does anyone have any ideas?

0 Kudos
1 Reply
martello
Contributor
Contributor

Here's one way:

use VMware::VIM2Runtime;

my $Server = $ARGV[0];

my $username = '';

my $password = '';

my $webserviceURL = '';

Vim::login(service_url => $webserviceURL,

user_name => $username,

password => $password);

my $vm = Vim::find_entity_view(view_type => 'VirtualMachine',

filter => { 'config.name' => "^$Server\$"});

if (! $vm) {

print "not found\n";

}

else{

my $VMID = (split(/-/, $vm->summary->vm->value))[1];

print "\nVM: $Server\nVMID: $VMID\n";

}

Vim::logout();

0 Kudos