如何清除Active Directory中的用户对象属性?

假设您使用simiple语法连接到Active Directory:

string adPath = "LDAP://server.domain.com/CN=John,CN=Users,dc=domain,dc=com"; DirectoryEntry userEntry = Settings.GetADEntry(adPath); 

现在您要查看该用户的属性,例如mail属性:

 Console.WriteLine("User's mail attribute is " + userEntry.Properties["mail"]); 

现在我该如何删除邮件属性值?

事实certificate这很简单,虽然不是很常用……

 string adPath = "LDAP://server.domain.com/CN=John,CN=Users,dc=domain,dc=com"; DirectoryEntry userEntry = Settings.GetADEntry(adPath); userentry.Properties["mail"].Clear(); userentry.CommitChanges(); 

不确定您是否可以删除它,因为用户对象通常遵循公司架构,但可能类似以下内容将起作用:

 userEntry.Properties["mail"] = null; 

或者可能:

 userEntry.Invoke("Put", "mail", null); 

然后:

 userEntry.CommitChanges();