JavaScript to Java Conversion Limitation in vRO

When vRealize Orchestrator runs scripts, the vCenter Server plug-in converts JavaScript arrays to Java arrays of a fixed size. As a result, you cannot add new values to vCenter Server data objects that take arrays as property values. You can create an object that takes an array as a property if you instantiate that object by passing it a pre-filled array. However, after you instantiate the object, you cannot add values to the array.

For example, the following code does not work:

var spec = new VcVirtualMachineConfigSpec();
spec.deviceChange = [];
spec.deviceChange[0] = new VcVirtualDeviceConfigSpec();
System.log(spec.deviceChange[0]); //Output undefined

In the above code, vRealize Orchestrator converts the empty spec.deviceChange JavaScript array into the fixed-size Java array VirtualDeviceConfigSpec[] before it calls setDeviceChange(). When calling spec.deviceChange[0] = new VcVirtualDeviceConfigSpec(), vRealize Orchestrator calls getDeviceChange() and the array remains a fixed, empty Java array.

Workaround: Declare the array as a local variable:

var spec = new VcVirtualMachineConfigSpec();
var deviceSpec = [];
deviceSpec[0] = new VcVirtualDeviceConfigSpec();
spec.deviceChange = deviceSpec;
System.log(spec.deviceChange[0]);
/* Output
DynamicWrapper (Instance) : [VcVirtualDeviceConfigSpec]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualDeviceSpec_Wrapper] -- VALUE : (vim.vm.device.VirtualDeviceSpec) {
   dynamicType = null,
   dynamicProperty = null,
   operation = null,
   fileOperation = null,
   device = null,
   profile = null,
   backing = null
}
*/

Disclaimer This article is drawn from Release Notes of vRealize Orchestrator 8.x and is added here just for educational purposes.


How to unlock AD User account using vRO

Scenario

Imagine you got a locked AD account and you don’t have access to Active Directory or don’t have rights to unlock your account but luckily have access to vRO or your colleague has access to the same vRO where your account’s AD is connected or maybe you just want to check and unlock an AD user account programmatically in your use-case (for eg. some service accounts that get locked every time you try to run something), What you should do? Just run a simple vRO script.

Solution

Create action and add input of type AD:User and paste 👇 script & execute it.

// Input AD:User
user.setAttribute('lockoutTime','0');
return user;

Steps

  • Create a new action and copy-paste the above script.
  • Add input User of type AD:User.
  • Save the action and Run it.
  • Select the user that you want to unlock and Click Run.

The action should execute successfully and your locked account is unlocked now.

Other attributes

  • Never expire account: user.setAttribute("accountExpires", NewDate);
  • Never expire password: user.setAttribute("userAccountControl", 66048);
  • Set email address: user.setAttribute("mail", strEmail);