2012-11-19 29 views
2

我有这样的代码,我可以更改显示名称,密码等,在Active Directory如何使用C#

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

我已经看过userPrincipal和属性来更改在Active Directory中的电话号码我找不到电话号码媒体资源。我的问题是如何在代码中更改用户的电话号码。

谢谢

回答

5

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

这是我做的......

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

谢谢。我会检查出来。 – arunlalam