4

I use this code for find users in AD

  SearchResultCollection results = null;
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                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["mail"].Value=txtemail.TemplateControl;
                user.Properties["description"].Value = txtnote.Text;
                user.CommitChanges();
                user.Invoke("SetPassword", new object[] { txtpass.Text });
            }

How do modify active directory user properties?

0

Check this post for detailed examples on how active directory properties are retrieved and updated - http://www.ianatkinson.net/computing/adcsharp.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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