DirectoryEntry de = new DirectoryEntry(someAdsiPath);
DirectorySearcher ds2 = new DirectorySearcher(de, "(objectCategory=user)");
using(de)
{
using (ds2)
{
ds2.SizeLimit = 50000;
ds2.PageSize = 1000;
ds2.PropertiesToLoad.Add("sAMAccountName");
foreach (SearchResult sr in ds2.FindAll())
{
//... do stuff
}
}
}
I'm not aware of whether or not the line setting SizeLimit is necessary. PageSize fixed the issue at a customer's site, and it's a bit impractical for me to test variations on SizeLimit.
Cheers,
Chris

No comments:
Post a Comment
Please keep it short, respectful, and clean!