简体   繁体   English

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

[英]How do I clear out a user object attribute in Active Directory?

Suppose you have connected to Active Directory using the simple syntax: 假设您使用简单语法连接到Active Directory:

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

Now, you find that you would like to see an attribute for that user. 现在,您发现您希望查看该用户的属性。 Let's try to display the mail attribute (which stands for email address): 让我们尝试显示邮件属性(代表电子邮件地址):

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

How can I delete the mail attribute value, since setting it to an empty string will not throw an error? 如何删除邮件属性值,因为将其设置为空字符串不会引发错误?

It turns out to be pretty simple, albeit not very commonly used... 事实证明这很简单,虽然不是很常用......

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

Not sure that you can delete it since user objects usually follow a company schema but maybe something like the following will work: 不确定您是否可以删除它,因为用户对象通常遵循公司架构,但可能类似以下内容将起作用:

userEntry.Properties["mail"] = null;

or maybe: 或者可能:

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

then: 然后:

userEntry.CommitChanges();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何读取Active Directory对象的User-Parameters属性的内容? - How can I read the content of the User-Parameters attribute of an Active Directory Object? 如何在C#中的Active Directory中的UserPrincipal对象上设置管理器属性 - How do I set the Manager Attribute on the UserPrincipal object in Active Directory in C# 如何使用.net中的nativeguid在Active Directory中找到用户? - How do I find a user in Active Directory using their nativeguid in .net? 如何在Active Directory中更新计算机对象上的managedBy属性? - How do I update the managedBy property on a computer object in Active Directory? 如何对 Active Directory 对象创建进行单元测试? - How do I unit test Active Directory object creation? 如何获取活动目录用户的“ ntSecurityDescriptor”对象 - How to get object of “ntSecurityDescriptor” of a active directory user 如何使用cmd在Active Directory中按CN找出用户的OU - How to find out OU of user by CN in Active Directory using cmd 如何使用LDAP从外部活动目录获取用户的组描述 - How do I get group description of a user from external active directory using LDAP 如何在Microsoft Active Directory中的OU中将新组应用于用户 - How do I apply a new group to a user in an OU in Microsoft Active Directory 如何使用 C# 以编程方式从 azure B2C Active Directory 中删除用户 - How do I delete a user from an azure B2C Active Directory programatically with C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM