1

I would like to get all users with their attributes from active directory I checked many topics includes Linq to LDAP + enter link description here

But all seems to be complicated.

I started with this:

public SearchResultCollection GetAllUsrs()
     {
         var dirEntry = new DirectoryEntry(string.Format("LDAP://{0}/{1}", "x.y.com", "DC=x,DC=y,DC=com"));
         var searcher = new DirectorySearcher(dirEntry)
         searcher.Filter = "(&(&(objectClass=user)(objectClass=person)))";
         searcher.PageSize = 999;

         return searcher.FindAll();

     }

How can i use pagging since the active directory will only return 1000 record at the time + how can i specify the attribute?

Problem: I want to query a domain that contain up to 60 K users with console application I want to specify the attribute Performance is very important. Can you please guide me to the best way to achieve this?

2 Answers 2

2

Paging is not required. AD will return more than 1000 objects. Leave PageSize at 0 and set SizeLimit as required. Use int.MaxValue ;) if you're unsure.

2
  • If i try to return more than 1000 record at the time, my account get blocked. i think it's a company policy.
    – Maro
    Jan 14, 2013 at 9:40
  • You mean it gets locked out? "net user %username% /domain" shows: Account active No? I've never heard of a query locking out an account if the supplied password is correct...
    – Daro
    Jan 15, 2013 at 10:47
2

Here's how you can do it with LINQ to LDAP:

using (var connection = new LdapConnection("x.y.com"))
{
     using (var context = new DirectoryContext(connection))
     {
          List<IDirectoryAttributes> users = context
               .Query("DC=x,DC=y,DC=com")
               .Where("(&(objectClass=user)(objectClass=person))")
               .InPagesOf(1000);
     }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.