【问题标题】:How do I change phone number in Active Directory using C#如何使用 C# 在 Active Directory 中更改电话号码
【发布时间】:2012-11-20 04:20:55
【问题描述】:

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

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

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

谢谢

【问题讨论】:

    标签: c# active-directory


    【解决方案1】:

    更正(抱歉所有修改):

    这就是我的工作......

        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();
        }
    

    【讨论】:

    • 谢谢。我去看看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多