3

我有这个代码,我可以在其中更改 Active Directory 中的显示名称、密码等

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

我查看了 userPrincipal 的属性,但找不到电话号码属性。我的问题是如何更改代码中用户的电话号码。

谢谢你

4

1 回答 1

6

更正(对不起所有的编辑):

这就是我所做的......

    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();
    }
于 2012-11-19T20:08:45.863 回答