Microsoft
Software
Hardware
Network
Question : DirectoryServices Listing User Groups
i am using the directoryservices class in vb.net and need to be able to return all the users that belong to a particular group.i have code that returns all groups that a user belongs to. here is the code that returns all groups that a user belongs to. in this example i am able to create a directory entry at the top of my domain and perform a search for the samAccountName. i want to be able to do the same but perform a search for the group name and return all members of that group.
Public sub Groups()
Dim directory, dir2 As DirectoryEntry
Dim searcher As DirectorySearcher
Dim sr As SearchResult
Dim rpc As ResultPropertyCollection
Dim i As Integer
Try
directory = New DirectoryEntry("LDAP://" & mvarDomain)
searcher = New DirectorySearcher(director
y, "(&(objectClass=user)(samA
ccountName
=" & mvarUserName & "))")
searcher.PropertiesToLoad.
Add("membe
rof")
sr = searcher.FindOne
rpc = sr.Properties
For i = 0 To (rpc.Item("memberof").Coun
t - 1)
dir2 = New DirectoryEntry("LDAP://" & rpc.Item("memberof").Item(
i).ToStrin
g)
MsgBox(dir2.Name)
Next
Catch ex As Exception
Throw (ex)
End Try
End Function
Answer : DirectoryServices Listing User Groups
Take a look at the "member" attribute in AD group schema class. And follow these steps
1. Bind to the given group object
2. Iterate through each member of the "member" attribute, extract and bind using its DN
Dim path As String = "LDAP://..."
Dim groupDN = "cn=admin,dn=...."
Dim group As DirectoryEntry = new DirectoryEntry(path + groupDN)
Dim dn As Object
For Each dn in group.Properties["member"]
Dim userDN As String = CType( dn, String.GetType() )
Dim user As DirectoryEntry = new DirectoryEntry(path + userDN)
Next dn
HTH
Random Solutions
combe SQL query
Boot.ini
LOAD DATA INFILE - TIMESTAMP, the correct usage
Memory Leak error, that only occurs, when i rename my server, and give a specific ip address?
_ReportOutput
How do I create static NAT on ISA Server 2006
How do I install Project 2007 to about 20 users via SMS.
Count records and give summary in an Access 2007 Report
How do I deploy Group Policy Preference Client Side Extensions for Windows XP
Showsound icon in notification area in Windows 7