Solved

vb.net list active directory groups

Posted on 2012-04-04
4
624 Views
Last Modified: 2012-04-09
Hi

I have problem with this code, some how i cant list all groups from domain.
Problem is that i have 70 groups in ad, example 10.100.product and 11.255.product .. etc...
but when im runnign this code it will only show me 42 groups so half of groups are missing, where could be the problem?

Imports System.DirectoryServices
Public Class Form1

    Public Shared Function GetDirectoryEntry() As DirectoryEntry

        Dim dirEntry As New DirectoryEntry("LDAP://domain")
        dirEntry.Username = Nothing
        dirEntry.Password = Nothing
        dirEntry.AuthenticationType = AuthenticationTypes.Secure
        Return dirEntry
    End Function

    Public Shared Function GetDirectorySearch() As DirectorySearcher
        Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
        Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
        Return dirSearcher
    End Function

    Private Sub exportfromad_Click(sender As System.Object, e As System.EventArgs) Handles exportfromad.Click
        Dim de As DirectoryEntry = GetDirectoryEntry()
        Dim deSearch As DirectorySearcher = New DirectorySearcher()
        deSearch.SearchRoot = de
        Dim test As String
        Dim count As Integer
        deSearch.Filter = "(&(objectClass=group) (samAccountName=" & "*" & "))"
        Dim results As SearchResultCollection = deSearch.FindAll()
        For Each r As SearchResult In results
            Try
                If r.GetDirectoryEntry.Name.Contains("product") Then
                    count += 1
                    test += r.GetDirectoryEntry.Name & vbCrLf
                End If
            Catch
            End Try
        Next
        MsgBox(test)
        MsgBox(count)
    End Sub
End Class

Open in new window

0
Comment
Question by:HaiFai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37805414
Have you tried adding a counter inside your foreach loop to make sure how many times your loop is running? You have an if condition and a silent catch block which may be the issue.
0
 
LVL 7

Author Comment

by:HaiFai
ID: 37805458
Thanks for fast reply.

Yes i have tried that and if i take all this off
 Try
                If r.GetDirectoryEntry.Name.Contains("product") Then
                    count += 1
                    test += r.GetDirectoryEntry.Name & vbCrLf
                End If
            Catch
            End Try

Open in new window


debug it and check results.count it will only show me 1000 results we have 1119 groups in ad, so somehow code wont see all groups...
0
 
LVL 7

Accepted Solution

by:
HaiFai earned 0 total points
ID: 37805658
found solution for this problem ... i needed to increase deSearch.PageSize and then it will find all
0
 
LVL 7

Author Closing Comment

by:HaiFai
ID: 37822697
default PageSize is 1000 if you have more than 1000 objects it will only find part of groups
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question