AD member of - recursive?

Hi,

I am trying to get a listing of the groups a user belongs to.

All is working well, except, if the user is in group a, and that group a is in group b, I can't get group b to show up in the retrieved list.

Here is part of my code. Can anyone help?

Dim de As DirectoryEntry

de = New DirectoryEntry("LDAP://DOMAIN/OU=DOMAIN USERS,OU=XX,DC=DOMAIN")
de.Username = "xxx"
de.Password = "xxx"
de.AuthenticationType = AuthenticationTypes.Secure Or AuthenticationTypes.ReadonlyServer
de.InitializeLifetimeService()

Dim oADSearcher As DirectorySearcher = New DirectorySearcher(de)
Dim oADResult As SearchResult

oADSearcher.PropertiesToLoad.Add("memberOf")
oADSearcher.Filter = "(&(sAMAccountName=SomeUser))"
oADResult = oADSearcher.FindOne()
If Not IsNothing(oADResult) Then
Dim MemberOfValue As String
For Each MemberOfValue In oADResult.Properties("memberOf")
Current.Response.Write(MemberOfValue & "<br />")
Next
End If

[1165 byte] By [Zolt] at [2007-12-21]
# 1

Hmmm, this is not really on topic for this forum but I will try to help you a bit.

Firstly, I found this example, might be what you are looking for:

http://www.netomatix.com/UserGroupMembership.aspx

What I am thinking is you would need to do a recursive search. For example, you would look through all the groups a user is a member of, then for each object found recursively enumerate all groups that it belongs to.

So write a function like so:

sub ListGroups(object entity)

' Loop through each group that entity is a member of.

' Print out group name.

' Call ListGroups on the group object

end sub

MattNeerincx at 2007-9-10 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2

Thanks Matt, I will give it a try.

I did not know in which group to put it under; it is about data access isn't it? :)

I did a search on AD in the MSDN forums and selected the forum name of the message which was closer to my type of request.

Anyway. I will let you know how it turned out.

Zolt

Zolt at 2007-9-10 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4

Thanks :)

BTW, I tried your sollution, and I got the same result as I had with my original code.

Now, what I need to find is a way to enumerate groups within a group.

This way, I could first get a list of groups a user belongs to, and then cascade this to a function returning groups within groups, and thus, get a complete list of groups the user belongs to.

..still looking for my solution.

Zolt

Zolt at 2007-9-10 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 5
I tried the this link http://www.netomatix.com/UserGroupMembership.aspx
but the result still 1 level only

it does not support nested universal groups
thank you

Dean at 2007-9-10 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified