use strict;
use warnings;
use Getopt::Long;
use VMware::VIRuntime;
use Term::ReadKey;
my %opts = (server => undef, username => undef,);
GetOptions (\%opts,"server=s", "username=s");
if( !defined ($opts{server} && $opts{username}) ) {
help();
exit (1);
}
ReadMode('noecho');
print "Enter $opts{username}\'s password: ";
my $password = ReadLine(0);
chomp $password;
ReadMode('normal');
# login
my $url = "https://" . $opts{server}. "/sdk/vimService";
Vim::login(service_url => $url, user_name => $opts{username}, password => $password);
# get VirtualMachine views for all powered on VM's
my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine');
# snapshot each VM
my $i;
foreach (@$vm_views) {
if( defined $_->snapshot ) {
print "-------------------------------------------------------------\n";
print $_->name . " has at least one snapshot defined . . . \n";
foreach $i (0 .. $#{$_->snapshot->rootSnapshotList} ) {
print "\t" . $_->snapshot->rootSnapshotList->[$i]->name . " @ " . $_->snapshot->rootSnapshotList->[$i]->createTime . "\n";
}
print "-------------------------------------------------------------\n";
}
}
# logout
Vim::logout();
sub help {
my $help_text = <<'END'; USAGE: query_snapshot.pl --server--user
Example:
query_snapshot.pl --server vc1 --user administrator
END
print $help_text;
}
Add-PSSnapin VMware.VimAutomation.Core
Get-VIServer vc1.example.com
Get-VM | % { $_.Name; Get-Snapshots $_ }
Labels: powershell, vmware
October 2007 November 2007 December 2007 January 2008 February 2008 April 2008 October 2009
Subscribe to Posts [Atom]