Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

csharp:directorysearcher1000

Der DirectorySearcher findet nur 1000 Ergebnisse

I am searching for existing logins using ADS Directory searcher findAll() method (as in following code). It appears the findall method returns only 1000 entries although there are more entries than that. How do I findAll() of every login ?
    IList<string> adslist = new List<string>();
    using (DirectoryEntry de = new DirectoryEntry("LDAP://armlink.com", null, null, AuthenticationTypes.Secure))
    using (DirectorySearcher ds = new DirectorySearcher(de, "(objectclass=user)", new string[] { "samaccountname" }))

        foreach (SearchResult sr in ds.FindAll())
        {
            string[] e = sr.Path.Split(new string[] { "LDAP://", "OU=", ",", "DC=", ".com", "/CN=" }, StringSplitOptions.RemoveEmptyEntries);
            ResultPropertyCollection pc = sr.Properties;
            adslist.Add(e[0] + "/" + pc["samaccountname"][0].ToString());
            //   Debug.WriteLine(adslist.Last());
        }

This is due to a server-side limit. From the DirectorySearcher.SizeLimit documentation:

The maximum number of objects that the server returns in a search. The default value is zero, which means to use the server-determined default size limit of 1000 entries.

And:
If you set SizeLimit to a value that is larger than the server-determined default of 1000 entries, the server-determined default is used.

Basically from this, it looks like unless there's a way of changing the server-side default, you're going to be limited to 1000 entries. It's possible that specifying a PageSize will let you fetch a certain number at a time, with a total greater than 1000… not sure.

By the way, it looks like you should also have a using directive around the SearchResultCollection:

using (SearchResultCollection results = ds.FindAll())
{
    foreach (SearchResult sr in results) 
    {
        ...
    }
}

Quelle: http://stackoverflow.com/questions/3488394/c-sharp-active-directory-services-findall-returns-only-1000-entries

csharp/directorysearcher1000.txt · Zuletzt geändert: 2016/04/02 00:48 (Externe Bearbeitung)