7Oct/110
vCenter Orchestrator Script – Increment VM Name by 1
Simple little code snippet that you might find handy to use in vCenter Orchestrator. I am working on a workflow that needs to clone a VM and the name should increment by 1 for example, we want to clone appweb1 (but we already have appweb2, 3, 4) so we want the new VM to be appweb5.
Inside a new Scriptable task create an output parameter called newvmname and make it's source itself. Then use this bit 'o code:
var vms = System.getModule("com.vmware.library.vc.vm").getAllVMsMatchingRegexp("appweb[0-9]");
for (var i=0; i System.debug("Counting VMs:" + i);
}
var newvmname = "appweb" + i;
If anyone has a better way to do this I'd love to hear it, I know you should be able to use the getAllVMsMatchingRegexp as an action inside the Schema but it seemed clunky to do that then pass to a Scriptable task when you can do it all in one object.
Related posts:
