views:

42

answers:

1

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.

+1  A: 

I have used OpenLDAP before so I am little bit familiar with filters and I found a Search Filter Syntax document which might help. Here is what I think might be possible:

(&(objectClass=user)(objectCategory=person)(cn>='a')(cn<='b'))

Let me know if it works.

Maxwell Troy Milton King
bluecoder
Both of you together are correct. This worked perfectly. Thank you very much.
Aaron