我有这个代码,我可以在Active Directory中更改显示名称,密码等
UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, userName);
userPrincipal.DisplayName = "Some NAME";
userPrincipal.SetPassword("NEW_PASSWORD");
userPrincipal.Save();
我查看了userPrincipal的属性,但找不到电话号码属性。我的问题是如何在代码中更改用户的电话号码。
谢谢
答案 0 :(得分: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();
}