VMware Cloud Community
BillStreet00
Enthusiast
Enthusiast

Adding a VM to an AD group during provisioning

We have a handful of AD groups used to patch Windows on various schedules.  I have a drop down that asks the user when they would like to patch and then I pass on the variables to a PS script. This works fine but it just bugs me that I have to use that PS script when I have everything else within vRO.  I did some googling and found one posting about this same thing back in 2015.  I took that code and some of my own and produced what I thought was a solid script.  However when it runs I get this message:

Error in (Workflow:JustTheProps / Scriptable task (item1)#74) TypeError: Cannot find function addElements in object DynamicWrapper (Instance) : [AD_UserGroup]-[class ch.dunes.ad.object.UserGroup] -- VALUE : #_v2_#,#UserGroup#,#012827d2-77fb-435f-bf6e-8fff3fcf4e76#,#XXXXXXXXXXXXXXXX

[2017-09-29 14:19:10.862] [E] Workflow execution stack:

***

item: 'JustTheProps/item1', state: 'failed', business state: 'null', exception: 'TypeError: Cannot find function addElements in object DynamicWrapper (Instance) : [AD_UserGroup]-[class ch.dunes.ad.object.UserGroup] -- VALUE : XXXXXXXXXX. (Workflow:Patching / Scriptable task (item1)#74)'

This is where the code bombs:

if (index == -1){

userGroup.addElements(computers);

System.debug(computerAD.name+" is added to group "+ userGroup.name);

}

else System.debug("Server is member of group "+userGroup.name);

Has anyone run into something similar and have an idea what needs to be looked at?

0 Kudos
3 Replies
iiliev
VMware Employee
VMware Employee

How do you populate the values of userGroup and computers variables? Are you sure they are correct?

Could you check if the OOTB workflow "Add computers to group members" works? It invokes the same API function as in your code.

0 Kudos
BillStreet00
Enthusiast
Enthusiast

Sorry for the late reply.  The OOTB workflow causes my workflow to throw:

[2017-10-03 14:37:49.465] [E] Error in (Workflow:Patching v4 / Scriptable task (item1)#1) TypeError: Cannot call method "get" of null

[2017-10-03 14:37:49.473] [E] Workflow execution stack:

When I remove the OOTB workflow and just perform the gets, it works fine.  I added some System.log() entries to track my progress and I am passing the right information to the OOTB workflow and the first workflow mentioned.  Neither work.

Originally I was just calling a PS script to add it to the right group but after upgrading to 7.3 that is broken as well.  The script and path are correct and verified.  vRA just errors on them.  When I try to run the same workflow I get this:

mmname : justoneplc

   patchingMethod : auto

   spbm_vc_password : XXX

   spbm_vc_sslthumbprint : ‎33 4a fe 67 b9 c5 c5 3a e2 0c df e8 b6 55 98 8f 5e 90 0a 39

   spbm_vc_username : XXXXX

   trace_id : wYw1WBoG

[2017-09-29 15:50:29.975] [I] Passing VM: p10justoneplc01 to the  auto patch group

[2017-09-29 15:50:34.493] [E] (com.vmware.library.powershell/invokeScript) Error in (Dynamic Script Module name : invokeScript#14) PowerShellInvocationError: Errors found while executing script

System.Management.Automation.CommandNotFoundException: The term '\\amwins.local\ScheduledTasks$\Scripts\ServerAutoDeploy\AddServer2PatchGrp.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)

   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)

   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)

It is getting frustrating when you get intermittent errors and nothing to show where the problem may lie.  I have a case open with SDK support but they are just as stumped as I am right now.

0 Kudos
BillStreet00
Enthusiast
Enthusiast

I worked with the OOTB workflow. Here is the code I used to get the patch group and computer objects. I confirmed this works consistently before adding the OOTB workflow.

var machine = payload.get("machine") ;

var vCACVmProperties = machine.get("properties") ;

var tempName = machine.get("name");

var tempUG= vCACVmProperties.get("patchingMethod");

var computers = new Array();

computers = ActiveDirectory.getComputerADRecursively(tempName);

System.log("Computer count: "+computers.length);

for each (pc in computers){

System.log("Checking computer: "+pc.name);

    if (tempName.toLowerCase() == pc.name.toLowerCase()){

    System.log("Found Computer: "+pc.name);

    }

}

var userGroupAD = ActiveDirectory.searchExactMatch("UserGroup",tmpUG,1);

for each (group in userGroupAD){

     userGroup = group;

}

That piece of the code works just fine.  I added the "Add computers to AD Group" workflow and promoted variables.  When I ran the workflow again this is what I got.

[2017-10-04 12:34:44.309] [E] Error in (Workflow:Patching2.1.1 / Scriptable task (item1)#12758) TypeError: Cannot call method "get" of null

[2017-10-04 12:34:44.317] [E] Workflow execution stack:

***

item: 'Patching2.1.1/item1', state: 'failed', business state: 'null', exception: 'TypeError: Cannot call method "get" of null (Workflow:Patching2.1.1 / Scriptable task (item1)#12758)'

workflow: 'Patching2.1.1' (56307de2-8952-41be-89a8-886df5bb999a)

|  'input': name=payload type=Properties value=null

I removed the workflow and I still get the same errors now. The code was working perfectly fine until I added that workflow.

If I duplicate the workflow it does not work.  If I create a new workflow and copy the code above to the new workflow then it works fine. Until I add the OOTB workflow then it breaks the whole workflow again.

0 Kudos