By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

retrieving 1000+ users from AD group using C#

P: 4
I am trying to retrieve 5000 users from AD group, but when I set PageSize= 1000 (or let's say 15000) and SizeLimit=15000, I still get only 1500 users. Any other configuration that I can set (I want to avoid range retrieval as suggested by MS) Please advice. Thanks Below is the code section: Please let me know what am I missing.
Jan 7 '16 #1
Share this Question
Share on Google+
5 Replies


P: 4
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3. searcher.SizeLimit=15000;
  4. searcher.PageSize = 1000; 
  5. return searcher.FindAll();
  6. }
Jan 7 '16 #2

100+
P: 299
What is your full code? It appears you likely have a problem with the search string, assuming there really is 5000 users and not only 1500.
Jan 7 '16 #3

P: 4
Expand|Select|Wrap|Line Numbers
  1. private SearchResultCollection ExecuteBestEffortSearch(DirectorySearcher searcher)
  2.     {
  3.       if (searcher == null) { throw new ArgumentNullException("searcher"); }
  4.       if (searcher.SearchRoot == null) { throw new ArgumentException("Directory Searcher does not have a search root.", "searcher"); }
  5.  
  6.       // Construct Search Message
  7.       string message = String.Format("[{0}] ({1}) with filter [{2}] for attributes [{3}]",
  8.         searcher.SearchRoot.Path, searcher.SearchScope, searcher.Filter, FlattenStringCollection(searcher.PropertiesToLoad));
  9.  
  10.       // Execute Search
  11.       try
  12.       {
  13.         if (Logger.DebugLevel >= Logger.MaxDebugLevel)
  14.         {
  15.           Logger.Debug(0, "Executing directory search for " + message, null, DirectoryServiceException.ModuleName, Logger.MaxDebugLevel);
  16.         }
  17.                 searcher.PageSize = 1000; //a positive number to turn off the default page limit in DirectorySearcher
  18.         return searcher.FindAll();
  19.  
  20.        }
  21.       catch (COMException adsiException)
  22.       {
  23.         DirectoryServiceException dsExeception = DirectoryServiceException.Create(
  24.           String.Format("The directory search {0} was unable to execute due to a directory service error.", message), adsiException);
  25.  
  26.         if (dsExeception is DirectoryServerUnavailableException)
  27.         {
  28.           try
  29.           {
  30.             Guid searchRootGuid = searcher.SearchRoot.Guid;
  31.             // Cleanup resources
  32.             searcher.SearchRoot.Dispose();
  33.             // Attempt to Re-Bind
  34.             using (DirectoryEntry searchRootEntry = GetEntryByGuid(searchRootGuid))
  35.             {
  36.                             searcher.PageSize = 1000; //a positive number to turn off the default page limit in DirectorySearcher
  37.               searcher.SearchRoot = searchRootEntry;
  38.               return searcher.FindAll();
  39.             }
  40.           }
  41.           catch (Exception ex)
  42.           {
  43.               Logger.LogError(30019, String.Format("The directory search {0} failed because the search root was unavailable and the server was not able to establish a new bind.", message), ex, DirectoryServiceException.ModuleName, Logger.MinDebugLevel);
  44.           }
  45.         }
  46.         throw dsExeception;
  47.       }
  48.     }
Jan 7 '16 #4

P: 4
And SizeLimit i am defining when i create an object of DirectorySearcher class
Jan 7 '16 #5

100+
P: 299
I'm still not seeing in your code where you supply a search filter to only grab user objects.
Jan 7 '16 #6

Post your reply

Sign in to post your reply or Sign up for a free account.