3

I have this code where I can change the display name, password, etc. in the Active Directory

UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, userName);
userPrincipal.DisplayName = "Some NAME";
userPrincipal.SetPassword("NEW_PASSWORD");
userPrincipal.Save();

I have looked at the properties of userPrincipal and I can not find the phone number property. My question is how do I change the phone number for the User in the code.

Thank You

1 Answer 1

7

Correction (Sorry for all the edits):

Here's what I do......

    public static void SetUserInfo(string userName)
    {
        var dsDirectoryEntry = new DirectoryEntry("LDAP://xxxx/DC=xx,DC=xxx", "ADusername", "ADpassword");

        var dsSearch = new DirectorySearcher(dsDirectoryEntry) { Filter = "(&(objectClass=user)(SAMAccountName=" + userName + "))" };

        var dsResults = dsSearch.FindOne();
        var myEntry = dsResults.GetDirectoryEntry();
        //myEntry.Properties[property].Value = value;
        myEntry.Properties["telephoneNumber"].Value = "222-222-2222";
        myEntry.CommitChanges();
    }
1
  • Thank you. I ll check it out.
    – arunlalam
    Nov 19, 2012 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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