views:

52

answers:

3

Hi guys,

I have a need to be able to identify all of the users on my AD (Active Directory) domain. I have the domain name and that is about it. It would rock if i could get it as a list of UserPrincipal or something but if its just a string then i can get the rest of the info i need from there.

Thanks!

+1  A: 

look to this article: How to: (Almost) Everything In Active Directory via C#

Michael Pakhantsov
+1 That looks like an excellent resource!
Chris Taylor
It is, just having trouble finding what i need. Probably the fault of my organization for having really crap AD implementation
TerrorAustralis
+1  A: 

I think you can use something like that:

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

If you just have to get the users list 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 have to more operations with AD you should consider using LINQ to AD API http://linqtoad.codeplex.com/

It is a Linq based API to work with AD. Easy to use and I have got some good results with it.

Unmesh Kondolikar
hey mate, how can i specify that i want object class NOT computer in that filter? my organization is pretty silly there
TerrorAustralis
NVM, found the syntax!
TerrorAustralis