vCO: List Virtual Machines with Snapshots


As a VMware administrator, making the VM snapshots under control is one of the critical tasks.

image

I wrote up a ‘List all VM with snapshot’ workflow which generate a report showing the virtual machines that have snapshots.

The key is in the scriptable task:

vmWithSnapshots = new Array();
var vms = VcPlugin.getAllVirtualMachines();
var logtext;

for(i in vms){
var vm = vms[i];
if(vm.runtime.connectionState.value==”connected” && !vm.config.template){
var actionResult = System.getModule(“com.vmware.library.vc.vm.snapshot”).getAllSnapshotsOfVM(vm);
if(actionResult.length > 0){
vmWithSnapshots.push(vm);
System.log(“VM name : ” + vm.name + ” – Number of snapshots : ” + actionResult.length);
logtext = “VM name : ” + vm.name + ” – Number of snapshots : ” + actionResult.length;
content = content + “<br>” + logtext;
}
}
}
vmsLength=vmWithSnapshots.length;
System.log(vmsLength + ” VM have snapshots”);
subjects = vmsLength + ” VM have snapshots”;

A email will be sent to the requester after the workflow is completed.

image

 

 

************************************************************************************************

TLV, this is FYI:

binding

Advertisement

7 thoughts on “vCO: List Virtual Machines with Snapshots

  1. [2013-10-06 11:43:03.900] [I] VM name : abc123 – Number of snapshots : 1
    [2013-10-06 11:43:03.937] [I] VM name : xyz123 – Number of snapshots : 1
    [2013-10-06 11:43:03.992] [I] VM name : 1234567 – Number of snapshots : 1
    [2013-10-06 11:43:04.088] [I] VM name : Abc3456 – Number of snapshots : 1
    [2013-10-06 11:43:04.127] [I] VM name : xrgz1234 – Number of snapshots : 1
    [2013-10-06 11:43:04.504] [I] VM name : 213123 – Number of snapshots : 1
    [2013-10-06 11:43:04.506] [I] 15 VM have snapshots
    [2013-10-06 11:43:04.639] [I] sending mail to host: :null with user:, from:, to:abc@123.com

    I received a blank email. Could you guide me, where i am going wrong.

  2. Thank you for the reply. What is the difference between “getAllSnapshotsOfVM” and “getAllSnapshotResultInDatastoreBrowser(false,false,false,true)”;

    Where can I find more information on com.vmware.library.vc.vm.snapshot and its examples.

  3. How can we specify particular vCenter name instead of all vC in “var vms = VcPlugin.getAllVirtualMachines();”
    Also how can we setup that email should be send to all users which have snapshot and each user should get only details of snapshot that he requested.

Leave a Reply to VMs Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s