VMware Cloud Community
sharptonm
Enthusiast
Enthusiast
Jump to solution

Simple Add computer account to group

Hey all,

I am trying to do something quite simple, or what should be simple.  I am trying to simply add a computer account to a group with vRA with vRO.  Sounds simple with this workflow, Add computers to group members.  However, I need to pass in strings. 

I have been able to get the strings converted (or I thought) to the proper complex data types/

AD:UserGroup

Array/AD:ComputerAD.

The computer account part works fine with this code (stolen from here)

var computers = ActiveDirectory.getComputerADRecursively(computerName);

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

for each (pc in computers){

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

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

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

  return pc;

  }

}


// Nothing found so throw exception:

throw "No matching Computer found: " + computerName;

I tried to do the same thing for the group with this code.

var userGroup = ActiveDirectory.searchExactMatch("UserGroup",userGroup_str,1);

System.log("Checking user: "+userGroup);

It fails.  When I click on the variable after the fact, I can see the computers variable looks proper as it has the DN, etc, etc.  When I view the other variable, it doesn't look right.  When using this code to add the elements (the account to the group)

userGroup.addElements(adServer);

I get this error.

015-05-21 15:08:26.669] [I] TypeError: Cannot find function addElements in object DynamicWrapper (Instance) : [AD_UserGroup]-[class ch.dunes.ad.object.UserGroup] -- VALUE : UserGroup rest of the group DN is here....

I am not handling the array properly, and I am obviously not an expert.  Any help would be greatly appreciated.

Reply
0 Kudos
1 Solution

Accepted Solutions
holashh
Enthusiast
Enthusiast
Jump to solution

Hi,

it really wierd bcs API writes it straight, well no worries, it has to be solved.

Try to download and use attached workflow, that is working for me and hope it helps you.

If you will have concerns or other questions, feel free to ask Smiley Wink.

H

View solution in original post

Reply
0 Kudos
10 Replies
holashh
Enthusiast
Enthusiast
Jump to solution

Hi,

maybe you miss something here:

var userGroup = ActiveDirectory.searchExactMatch("UserGroup",userGroup_str,1);


userGroup_str has to be quotated so correct is "userGroup_str" than you can check it in log but be aware that exactMatch returns ARRAY so you should iterate on it:

for each (group in userGroup){

     adGroup = group;

}

and than should also work adGroup.addElement() method.


Give this chance and try, check also the API explorer.


Cheers


Reply
0 Kudos
sharptonm
Enthusiast
Enthusiast
Jump to solution

Thanks very much for your reply.  I saw that it needed quotes but, it does not appear to honor my variable when I have the quotes there.

I have userGroup_str as in input which will be the group name string passed by the user, or vRA.  I match exactly to the group name from the input.  This will be a vRA property that will be mapped to this string.  I will do the same for the computer account name.  I then pass this, and no group is found.

var userGroup = ActiveDirectory.searchExactMatch("UserGroup","userGroup_str",1);

System.log("Group count: "+userGroup.length);

for each (group in userGroup){

     adGroup = group;

}

System.log("List group: "+adGroup);

Log shows this.

[2015-05-22 08:00:26.484] [I] Group count: 0

[2015-05-22 08:00:26.484] [I] List group: null

If I remove the quotes, the group is found and listed, but is not an array?

[2015-05-22 08:01:27.179] [I] Group count: 1

[2015-05-22 08:01:27.179] [I] List group: DynamicWrapper (Instance) : [AD_UserGroup]-[class ch.dunes.ad.object.UserGroup] -- VALUE : UserGroup:CN=groupname,OU=Groups,OU=removed,OU=Users and Groups,DC=na,DC=removed,DC=com

[2015-05-22 08:01:27.179] [I] Workflow:Get AD Computer by String Name / Scriptable task (item1) : ch.dunes.model.type.ConvertorException: Not an Array


I also decided to change over to this code to convert the computer from string to array ad computer complex data type, the same issue occurs with this one.

computerName is an input variable here from the user, or from a vRA property.

var computers = ActiveDirectory.searchExactMatch("ComputerAD",computerName,1);

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

for each (pc in computers){

     adServer = pc;

}

System.log("List Computer: "+adServer);

Log shows this with out the quotes on my variable.

[2015-05-22 08:08:03.050] [I] Computer count: 1

[2015-05-22 08:08:03.050] [I] List Computer: DynamicWrapper (Instance) : [AD_Computer]-[class ch.dunes.ad.object.Computer] -- VALUE : ComputerAD:CN=removed,OU=Lab,OU=removed,OU=removed,OU=removed,DC=removed,DC=removed,DC=com

[2015-05-22 08:08:03.050] [I] Workflow:Get AD Computer by String Name / Scriptable task (item3) : ch.dunes.model.type.ConvertorException: Not an Array

Add the quotes, this happens.

[2015-05-22 08:09:25.831] [I] Computer count: 0

[2015-05-22 08:09:25.832] [I] List Computer: null

Hoping this is something simple.  Variable is not honored, and then when it is (if I hard code the group/computer namne), it doesn't think the output is an array.  If I hard code the group name and computer name, it does not think the output is an array.  Your help is greatly appreciated.

Reply
0 Kudos
sharptonm
Enthusiast
Enthusiast
Jump to solution

Also, if you have a working workflow, please share it.  Thanks!

Reply
0 Kudos
holashh
Enthusiast
Enthusiast
Jump to solution

Hi,

it really wierd bcs API writes it straight, well no worries, it has to be solved.

Try to download and use attached workflow, that is working for me and hope it helps you.

If you will have concerns or other questions, feel free to ask Smiley Wink.

H

Reply
0 Kudos
sharptonm
Enthusiast
Enthusiast
Jump to solution

Thank you very much for this.  I still want to pass in the group name as a string, but it appears you cannot pass a variable here, as vCO will not honor it.

userGroupAd = ActiveDirectory.searchExactMatch("UserGroup","thisWouldBeANiceVariable",1);

for each (group in userGroupAd){

  userGroup = group;

}

Again, thanks!

Reply
0 Kudos
holashh
Enthusiast
Enthusiast
Jump to solution

Hi,

well I think that it should work, if you pass thisWouldBeANiceVariable as a string in to scriptable box.

To be honest I never use this by this way, I will try it and let you know, if I share some time fot it.

BR,

Jan

Reply
0 Kudos
holashh
Enthusiast
Enthusiast
Jump to solution

And here I am, look into "_v2" WF, where it is as input variable (string).

I added some debug outputs you can use for testing, it is working for me. But here is any handling of typoes or error warn about AD group presentation.

Enjoy!

J

sharptonm
Enthusiast
Enthusiast
Jump to solution

Sorry for the major delay.  All is working, thanks for your help with this!

Reply
0 Kudos
mvr007
Contributor
Contributor
Jump to solution

I am getting the below error message

"Cannot convert  to com.vmware.o11n.plugin.ad.model.AdHost (Workflow:Add computers to AD group members"

Does it work with AD plugin 2 (GA release) ? Appreciate any inputs here.

Reply
0 Kudos
holashh
Enthusiast
Enthusiast
Jump to solution

It is working also with vRO6.0.2 with AD plugin "Active Directory 1.0.6.2315152"

Do you have AD host configured in your orchestrator? Try to get AD group in first step from plugin and then try to resolve it with add of element (computer/user/whatever)

Cheers

Reply
0 Kudos