Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Suppose you have connected to Active Directory using the simple syntax:

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?

like image 714
Dscoduc Avatar asked Jul 29 '09 02:07

Dscoduc


1 Answers

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();
like image 75
Dscoduc Avatar answered Oct 04 '22 16:10

Dscoduc