[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

vb.net list active directory groups

Posted on 2012-04-04
4
Medium Priority
?
727 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 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