cloerner
Enthusiast
Enthusiast

AD Plugin - Find Groups of an User

Jump to solution

Hello,

I am still trying to get more informations of an user from AD. I tryed the following code with an AD_User as Input:

var test = User.memberOf;

System.log(test);

But the result is:

[2014-03-10 21:04:53.854] [I] undefined

The server.log says the following:

[DynamicWrapper] Property named 'memberOf' not found on object : AD_User

But I know that this property exists in AD_User.Can someone please help me out?

Thanks in advance.

Chris

0 Kudos
1 Solution

Accepted Solutions
Jalapeno420
Enthusiast
Enthusiast

If you are getting the user via the search as below it returns an array so you need to reference the first, or appropriate, element of the array.

userObject = ActiveDirectory.search("User", userId);

for each (group in userObject[0].memberOf) {

  System.log(group.id);

}

View solution in original post

0 Kudos
4 Replies
Jalapeno420
Enthusiast
Enthusiast

If you are getting the user via the search as below it returns an array so you need to reference the first, or appropriate, element of the array.

userObject = ActiveDirectory.search("User", userId);

for each (group in userObject[0].memberOf) {

  System.log(group.id);

}

0 Kudos
cloerner
Enthusiast
Enthusiast

Hello Jalapeno420,

I used your code above, bu I still get this error.

[2014-03-13 10:50:34.063] [I] TypeError: Cannot read property "memberOf" from undefined (Workflow:GetUserGroups / Scriptable task (item1)#2)

Edit:

It works. I used an AD_User for the search. This was my error.

0 Kudos
igaydajiev
VMware Employee
VMware Employee

Maybe userObject = ActiveDirectory.search("User", userId); is not able to find user with provided suerId.

I have tested with following script

------------------------------------------

users = ActiveDirectory.search("User", userId);

System.log("Found " + users.length + " users with id " + userId);

for each (user in users) {

System.log("User " + user.name + "  - " + user.accountName);

groups =  user.memberOf

for each (group in groups) {

  System.log(group.id);

}

}

----------------

2014-03-17 09:16:47.899] [I] Found 1 users with id igaydajiev

[2014-03-17 09:16:47.899] [I] User Ivo Gaydajiev  - igaydajiev

[2014-03-17 09:16:47.910] [I] UserGroup:CN=test,OU=Test Accounts,OU=vco,DC=gia,DC=net

[2014-03-17 09:16:47.910] [I] UserGroup:CN=vCO Admins,OU=vCO Admins,OU=vco,DC=gia,DC=net

[2014-03-17 09:16:47.910] [I] UserGroup:CN=vcousers,OU=vCO Users,OU=vco,DC=gia,DC=net

[2014-03-17 09:16:47.910] [I] UserGroup:CN=Domain Users,CN=Users,DC=gia,DC=net

0 Kudos
Dean13
Contributor
Contributor

Hello @igaydajiev.

I attempted to use your test code today but was unable to get it to return the group IDs like in your example.  It returned the user name and account name, but for the groups, it returned undefined.  I know the account is a member of several AD groups, so I am not sure why it is not returning valid results.

I am using AD plug-in version 2.0.0.

Do you have any suggestions?

0 Kudos