Get all users from AD domain

I need to be able to identify all users in my AD (Active Directory) domain. I have a domain name, and that’s it. It will download if I can get it as a UserPrincipal list or something like that, but if its just a string, then I can get the rest of the information I need from there.

Thank!

+2
source share
3 answers

If you just need to get a list of users, you can use this code -

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();

However, if you need more AD operations, you should use the LINQ to AD API http://linqtoad.codeplex.com/

API, Linq, AD. , .

+5

I think you can use something like this:

DirectoryEntry domain = new DirectoryEntry("LDAP://domain.com/CN=Users,DC=Domain,DC=com");
foreach (DirectoryEntry child in domain.Children)
{
    // code
}
+2
source

All Articles