vRealize Orchestrator, VMs that Need Consolidation

May 6, 2015 0 By Allan Kjaer

I was creating a workflow that could find VM’s that need consolidation and the consolidate them.

I did not find any actions or workflow for this so i created one, with this script:

System.log("Removing Consolidated Needed snapshots");

for each (var vcenter in vcenters) {
	var vms = vcenter.getAllVirtualMachines();
	for each (var vm in vms) {
		if(vm.runtime.connectionState.value=="connected" && !vm.config.template) {
			if(vm.runtime.ConsolidationNeeded) {
				System.log("Consolidate VM Name: " + vm.name);
				var task = vm.consolidateVMDisks_Task(true);
				var actionResult = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task);
			}
		}
	}
}

This is just a sample workflow, you can modify for your own usage, test before using it.

Download: Finds-VM-that-Needs-Consolidation-and-Consolidate-them.zip

Please share this page if you find it usefull: