I've got to modify a property in active directory for each user throughout the company I work for. This is the code that I am user to get all users.
String domain = Properties.Settings.Default.ADConn;
String user = Properties.Settings.Default.ADAdmin;
String pass = Properties.Settings.Default.ADPass;
DirectoryEntry ADEntry = new DirectoryEntry(domain, user, pass);
DirectorySearcher ADSearcher = new DirectorySearcher(ADEntry);
ADSearcher.Filter = "(&(objectClass=user)(objectCategory=person))";
SearchResultCollection allResults = ADSearcher.FindAll();
foreach (SearchResult result in allResults)
{
DirectoryEntry deUser = result.GetDirectoryEntry();
//....Do stuff here
There are a large amount of people in the company, and so it was requested that I split the users alphabetically and handle one chunk of users at a time. For example, change properties for users [A-G], then [H-N], then [O-Z]. How can I modify my filter to give me users X through Y?
EDIT: My Final result was to do the following:
ADSearcher.Filter = "(&(objectClass=user)(objectCategory=person)(sAMAccountName>=X)(sAMAccountName<=Y))";
Thank you very much for your help.