SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use this code for find users in AD

  SearchResultCollection results = null;
                System.DirectoryServices.DirectoryEntry entry = new DirectoryEntry("LDAP://...");
                DirectorySearcher adSearcher = new DirectorySearcher(entry);
                adSearcher.SearchScope = SearchScope.Subtree;
               adSearcher.Filter = "(&(objectClass=user)(sAMAccountName=" + userName + "))";

                results = adSearcher.FindAll();
        catch (Exception e)


and add a Children

 using (DirectoryEntry ou = new DirectoryEntry("LDAP://Domainname"))

                DirectoryEntry user = ou.Children.Add("CN=" + txtuser.Text, "user");
                int NORMAL_ACCOUNT = 0x200;
                int PWD_NOTREQD = 0x20;
                user.Properties["sAMAccountName"].Value = txtuser.Text;
                user.Properties["userAccountControl"].Value = NORMAL_ACCOUNT | PWD_NOTREQD;
                user.Properties["displayName"].Value = txtname.Text;
                user.Properties["description"].Value = txtnote.Text;
                user.Invoke("SetPassword", new object[] { txtpass.Text });

How do modify active directory user properties?

share|improve this question
up vote 0 down vote accepted

Check this post for detailed examples on how active directory properties are retrieved and updated -

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.