AD Group Ownership

G

Guest

I am trying to use the following button code to allow a user to enter an
Active Directory account name and then have the system return the specified
user' group memberships and the "ManagedBy" value for each group membership.
Has anyone done this before? As it stands now it will just give back the
group memberships and no "ManagedBy" values. Thanks for all your helpl.
This code is from a button:
CheckedListBox3.Items.Clear()
Dim strDomain As String
Dim rootds As New DirectoryServices.DirectoryEntry("LDAP://rootDSE")
strDomain = rootds.Properties("DefaultNamingContext")(0)
Dim root As New System.DirectoryServices.DirectoryEntry("LDAP://" &_
strDomain)
Dim searcher As New System.DirectoryServices.DirectorySearcher(root)
Dim searchero As New System.DirectoryServices.DirectorySearcher(root)
searcher.Filter = "(&(objectCategory=user)(anr=" & TextBox3.Text & "))"
Dim results As System.DirectoryServices.SearchResultCollection
results = searcher.FindAll()
Dim result As System.DirectoryServices.SearchResult
For Each result In results
Dim User As New System.DirectoryServices.DirectoryEntry(result.Path)
Dim group As String
Dim count As Integer = 0
For Each group In (User.Properties("memberof"))
TextBox4.Text = TextBox4.Text & count & " / "
CheckedListBox3.Items.Add(User.Properties("memberof").Item(count))
searchero.Filter = "(&(objectCategory=group)(anr=" &_
User.Properties("memberof").Item(count) & "))"
Dim resulto As System.DirectoryServices.SearchResultCollection
resulto = searchero.FindAll()
Dim item As System.DirectoryServices.SearchResult
For Each item In resulto
Dim owner As New System.DirectoryServices.DirectoryEntry(item.Path)
'TextBox4.Text = TextBox4.Text & count & " / "
CheckedListBox3.Items.Add(owner.Properties.Values)
Next
count = count + 1
Next
User = Nothing
Next result
 
M

Marc Scheuner [MVP ADSI]

I am trying to use the following button code to allow a user to enter an
Active Directory account name and then have the system return the specified
user' group memberships and the "ManagedBy" value for each group membership.
Has anyone done this before? As it stands now it will just give back the
group memberships and no "ManagedBy" values.

You cannot do this in one step, unfortunately - you cannot query the
user's "memberOf" attribute and in the same search also "join in" the
group's "ManagedBy" attribute (like in a SQL Join).

What you can do (if you REALLY need this) is to enumerate the user's
"memberOf" property, and for each group found, bind to the group and
get it's "managedBy" property. Won't be very fast though! (lots of
costly bind operations).

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top