jasonbrandt3
asked on
C# Filter AD search
I'm searching AD for user accounts that were created on or after a certain date, I'd like to just pull in the login id (samAccount). Not sure how to modify the attached code to accomplish this. Learning C# on the fly! Thanks for any assistance.
public class MainClass {
public static void Main() {
using (DirectoryEntry de = new DirectoryEntry("LDAP://yourV/OU=yourV, DC=explorer, DC=local"))
using (DirectorySearcher searcher = new DirectorySearcher()) {
de.Username = @"explorer\yourName";
de.Password = "password";
searcher.SearchRoot = de;
searcher.Filter = "(&(objectClass=user)(description=Auth*))";
searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
searcher.PropertiesToLoad.Add("name");
searcher.PropertiesToLoad.Add("description");
searcher.PropertiesToLoad.Add("givenName");
searcher.PropertiesToLoad.Add("wWWHomePage");
searcher.Sort = new SortOption("givenName", SortDirection.Ascending);
SearchResultCollection results = searcher.FindAll();
foreach (SearchResult result in results) {
ResultPropertyCollection props = result.Properties;
foreach (string propName in props.PropertyNames) {
Console.Write(propName + ": ");
Console.WriteLine(props[propName][0]);
}
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
where would I put that? What about searchng by whenCreated?
ASKER