vRO convert objects from string to object type

This code can be used to convert a vDS portgroup name in type string to a vDS portgroup object in type VC:DistrubutedVirtualPortgroup

You can use this to convert anything by calling the appropriate methods and querying the appropriate value.

Here we call theĀ getAllDistributedVirtualPortgroups() method to get all vDS portgroups but you could call the getAllVirtualMachines() or getAllDatastores() method.

Set an input parameter of pgName in type string and the output Parameter as nicnetwork of type VC:DistrubutedVirtualPortgroup

The vDS portgroup .name value will have the vDS name in brackets after the portgroup in a similar format to “MyPortgroup (myVDS)”

So the input string would have to be represented in this way to work or you’d need to elaborate on the java script.


var portgroups = VcPlugin.getAllDistributedVirtualPortgroups();

var arraylength = portgroups.length;
var i = 0;

while (i < arraylength){ if (portgroups[i].name == pgName){ nicnetwork = portgroups[i]; }

i++;

}

Advertisements