Hi All,
Hoping someone has already done this. I want to create a workflow that will shutdown all vm's in Tenant1 folder. The problem is that if you use the getAllVirtualMachinesbyFolder it does not perform a recursive search. So in this example it will find no virtual machines.
Does someone have a workflow example that will do the action recursively?
Hi,
There is an action getAllVirtualMachinesByFolderIncludingSubFolders that takes a VmFolder input parameter and returns an array with virtual machines in this folder and its subfolders (performing a recursive search).
Here is the action's scripting code for reference:
if (!vmFolder) {
throw "UndefinedParameter: vmFolder mandatory input is not defined.";
}
var allVms = new Array();
getAllVmsInFolder(vmFolder);
return allVms;
function getAllVmsInFolder(folder) {
var children = folder.childEntity;
for (var i in children) {
if (children[i] instanceof VcFolder) {
getAllVmsInFolder(children[i]);
}
if (children[i] instanceof VcVirtualMachine) {
allVms.push(children[i]);
}
}
}
Hi,
There is an action getAllVirtualMachinesByFolderIncludingSubFolders that takes a VmFolder input parameter and returns an array with virtual machines in this folder and its subfolders (performing a recursive search).
Here is the action's scripting code for reference:
if (!vmFolder) {
throw "UndefinedParameter: vmFolder mandatory input is not defined.";
}
var allVms = new Array();
getAllVmsInFolder(vmFolder);
return allVms;
function getAllVmsInFolder(folder) {
var children = folder.childEntity;
for (var i in children) {
if (children[i] instanceof VcFolder) {
getAllVmsInFolder(children[i]);
}
if (children[i] instanceof VcVirtualMachine) {
allVms.push(children[i]);
}
}
}
Thank you!
That worked perfect!
RS