List All Members in an Active Directory into DropdownList - VB.NET RRS feed

  • Question

  • User-1877600661 posted


    Can anyone help me with this one as I'm a bit stuck. I found this code on the internet but I'm not sure how to use it:

    Public Sub ListADGroupMembers()
                Dim DirectoryRoot As New DirectoryEntry("LDAP://RootDSE") {not sure what is suppose to be within the brackets?}
                Dim DNC = DirectoryRoot.Properties("DefaultNamingContext")(0).ToString() {what is the DefaultNamingContext?}
                Dim GroupName As String = "Group Name" {is this the name of the active directory group?}
                Dim GroupMembers As System.Collections.Specialized.StringCollection = GetGroupMembers(DNC, GroupName)
                For Each Member As String In GroupMembers
                Next Member
    End Sub
    Public Function GetGroupMembers(ByVal strDomain As String, ByVal strGroup As String) As System.Collections.Specialized.StringCollection
                Dim GroupMembers As New System.Collections.Specialized.StringCollection()
                    Dim DirectoryRoot As New DirectoryEntry("LDAP://" & strDomain)
                    Dim DirectorySearch As New DirectorySearcher(DirectoryRoot, "(CN=" & strGroup & ")")
                    Dim DirectorySearchCollection As SearchResultCollection = DirectorySearch.FindAll()
                    For Each DirectorySearchResult As SearchResult In DirectorySearchCollection
                        Dim ResultPropertyCollection As ResultPropertyCollection = DirectorySearchResult.Properties
                        Dim GroupMemberDN As String
                        For Each GroupMemberDN In ResultPropertyCollection("member") {is it "member" in all instances?}
                            Dim DirectoryMember As New DirectoryEntry("LDAP://" & GroupMemberDN)
                            Dim DirectoryMemberProperties As System.DirectoryServices.PropertyCollection = DirectoryMember.Properties
                            Dim DirectoryItem As Object = DirectoryMemberProperties("sAMAccountName").Value {what is "sAMAccountName"?}
                            If Nothing IsNot DirectoryItem Then
                            End If
                        Next GroupMemberDN
                    Next DirectorySearchResult
                Catch ex As Exception
                End Try
                Return GroupMembers
    End Function

    I have indicated values which I don't know what I need to put in bolded text against the code line.

    Much appreciate it if anyone could help me with the active directory stuff as this is the first time which I have explored this area.

    Thanks in advance!

    Monday, March 29, 2010 11:46 PM

All replies