views:

271

answers:

2

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

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

Now you want to see an attribute for that user, say the mail attribute:

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

Now how can I delete the mail attribute value?

A: 

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();
Jay
+1  A: 

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