As a VMware administrator, making the VM snapshots under control is one of the critical tasks.
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.
************************************************************************************************
TLV, this is FYI:
Hi,
Could you brief about the parameters/attributes defined in the scripts.
[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.
Hi tlv, I think you did not set the binding correctly. Check this out: https://jackiechendotorg.files.wordpress.com/2013/05/binding.png
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.
I get invalid character on line 6…
Is there a way to tell who created the snapshot?
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.