如何使用C#更改Active Directory中的电话号码

3
我有这样一段代码,可以在Active Directory中更改显示名称、密码等信息。
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, userName);
userPrincipal.DisplayName = "Some NAME";
userPrincipal.SetPassword("NEW_PASSWORD");
userPrincipal.Save();

我查看了userPrincipal属性,但未找到电话号码属性。我的问题是,我该如何在代码中更改用户的电话号码。
谢谢。
1个回答

7
对不起,我进行了多次编辑,以下是我的做法......
这是我的解决方案......
    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();
    }

谢谢。我会去看看。 - arunlalam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接