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]; }



vRO Return Datastores over a specified TB size

This code will return only the datastores over a specified Terabyte size.

Set two input parameters

inputTB as type number, this will be the TB size that will determine the Datastores to return.

set another input parameter as inDS as array type VC:Datastore

Set the output parameter as outDS as array type VC:Datastore

var tbSize = inputTB * 1073741824;

System.log("Variable tbSize is "+tbSize);

var ds = new Array();

for each (d in inDS){ if (d.summary.capacity >= tbSize){ ds.push(d);} System.log("name: " + d.name +" Size: "+ d.summary.capacity);}

outDS = ds;

vRO vMotion VM to SDRS Datastore cluster and inflate disk

The following can be used to vMotion a machine to an SDRS Datastore Cluster, inflating the disk to Lazy Zero at the same time (done by VcVirtualMachineRelocateTransformation.flat)

Create two input parameters. vMotionVM of type VC:VirtualMachine & a parameter name SDRSCL of type VC:StoragePod

The output parameter will be myVcTask of type VC:Task

var storageSpec = new VcStoragePlacementSpec();
var StorageResourceManager = vMotionVM.sdkConnection.storageResourceManager;
var myStoragePlacementResult = VcStoragePlacementResult();
var myKey = new Array();
var podSelectionSpec = new VcStorageDrsPodSelectionSpec();
var relocateSpec = new VcVirtualMachineRelocateSpec();
relocateSpec.transform = VcVirtualMachineRelocateTransformation.flat;

podSelectionSpec.storagePod = SDRSCL;

storageSpec.type = "relocate";
storageSpec.vm = vMotionVM;
storageSpec.podSelectionSpec = podSelectionSpec;
storageSpec.relocateSpec = relocateSpec

myStoragePlacementResult = StorageResourceManager.recommendDatastores(storageSpec);

myKey[0] = myStoragePlacementResult.recommendations[0].key
myVcTask = StorageResourceManager.applyStorageDrsRecommendation_Task(myKey);

vRO Remove CD ROM Workflow

The following can be used to remove a CDROM drive from a powered on Virtual Machine using vRO, vRealize Orchestrator.

Paste the following into a Scriptable task and create an input Parameter of type VC:VirtualMachine called workflowVM


var configSpec = new VcVirtualMachineConfigSpec();
var deviceConfigSpecs = new Array();
var deviceConfigSpec = new VcVirtualDeviceConfigSpec();
var devices = workflowVM.config.hardware.device;

for ( var ii in devices) {
var device = devices[ii];
if ( device instanceof VcVirtualCdrom) {
deviceConfigSpec.device = device;
deviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.remove;
deviceConfigSpecs.push (deviceConfigSpec);
configSpec.deviceChange = deviceConfigSpecs