c# LDAP Delete Active Directory user
16/04/2010 Leave a comment
Usage:
UserDn : ldap path of the user account which is gonna delete.
admin : Priviledged user to delete mean admin account
adminpass : you know what is this 🙂
Example:
DeleteUser(“LDAP://umbrella.com,CN=UserToDelete,OU=PORTAL,DC=TestDomain,DC=Service,DC=Local”,”TestDomain\\Admin”,”secret”);
public static void DeleteUser(string userDn, string admin, string adminpass)
{
try
{
DirectoryEntry user = new DirectoryEntry(userDn, admin, adminpass);
user.DeleteTree();
user.Close();
}
catch (System.DirectoryServices.DirectoryServicesCOMException ex)
{
//DoSomethingWith
}
}