Hi,
Check the following vRO scripting code. Its input is the variable vm of type VC:VirtualMachine.
if (vm != null
&& vm.runtime.connectionState.value == "connected"
&& !vm.config.template
&& vm.runtime.consolidationNeeded) {
System.log("Consolidating disks of VM: " + vm.name);
var task = vm.consolidateVMDisks_Task();
var waitResult = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task);
}