Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1725
  • Last Modified:

How can I get a list of groups in Active Directory and find out who is in those groups

I would like to be able to find out the names of all the active directory groups in my company and who is in those groups.  How would I do this using Visual Studio 2005 Visual Basic and .NET 2.0?   I tried with the below sample code but specifying "ou=Groups" does not do anything.  If I use something in the filter like sn=mar* then I do get the proper listing of names for the wildcard.  Maybe I should be using something other than "ou=" to find the groups?  I need a solution that uses VS 2005 Visual Basic and .NET 2.0

        Dim aADE As New DirectoryEntry("LDAP://myADNodePath")
        Dim aDS As New DirectorySearcher(aADE)
        Dim aSearchResult As SearchResult
        aDS .Filter = ("(ou=Groups)") '
        Dim aSRC As SearchResultCollection
        aSRC = aDS .FindAll()

        For I1 As Integer = 0 To aSRC .Count - 1
            aSearchResult = aSRC .Item(I1)
            ListBox1.Items.Add(aSearchResult.Path)
        Next
0
zonkerman
Asked:
zonkerman
2 Solutions
 
ZavatarCommented:
Try objectClass=group
0
 
AkisCCommented:
       Dim strDomain As String = "youDomain.com", tmp As String = ""
        Dim Computer As Object, Group As Object
        Computer = GetObject("WinNT://" & strDomain)
        For Each Group In Computer
            If (Group.Class = "Group") Then
                tmp &= Group.Name & vbCrLf
            End If
        Next
        MsgBox(tmp)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now