DirectoryEntry rootEntry = new DirectoryEntry("LDAP://NESTIT-283:389"); rootEntry.AuthenticationType = AuthenticationTypes.None; //Or whatever it need be DirectorySearcher searcher = new DirectorySearcher(rootEntry); string searchString = "(CN = EFTS-CA-TEST)"; var queryFormat = "(&(objectClass=user)(objectCategory=person)(|(SAMAccountName=*{0}*)(cn=*{0}*)(gn=*{0}*)(sn=*{0}*)(email=*{0}*)))"; //searcher.Filter = string.Format(queryFormat, searchString); searcher.Filter = searchString;//Search how you want. Google "LDAP Filter" for more. foreach (SearchResult result in searcher.FindAll()) { Console.WriteLine("account name: {0}", result.Properties["samaccountname"].Count > 0 ? result.Properties["samaccountname"][0] : string.Empty); Console.WriteLine("common name: {0}", result.Properties["cn"].Count > 0 ? result.Properties["cn"][0] : string.Empty); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)