5

The question basically says it all. I want to be able to get a list of all the users on the windows domain (i.e. in the active directory) using c#.

Thanks!

adhanlon
  • 6,407
  • 13
  • 43
  • 41
  • Might be easier to do things on the SQL side (generate a view of all users). Can I assume you are willing to use SQL Server? – Spooks Feb 08 '11 at 20:38
  • I am using SQL Server as well, but my authentication must be with the windows domain – adhanlon Feb 08 '11 at 21:08

1 Answers1

5
var dirEntry = new DirectoryEntry(string.Format("LDAP://{0}/{1}", "x.y.com", "DC=x,DC=y,DC=com"));
var searcher = new DirectorySearcher(dirEntry)
         {
             Filter = "(&(&(objectClass=user)(objectClass=person)))"
         };
var resultCollection = searcher.FindAll();

SEE: Get all users from AD domain

Community
  • 1
  • 1
John K.
  • 5,426
  • 1
  • 21
  • 20
  • Thanks, that is helpful. How do I know what needs to be passed into the constructor of the DirectoryEntry object? I'm confused about the parameters of that string. – adhanlon Feb 08 '11 at 20:40
  • Those are your AD Company identifiers. Company Name, Company Country...etc. – Spooks Feb 08 '11 at 20:45