c# LDAP Delete Active Directory user


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 
     }
}
Advertisement

About bpostaci
Escalation Engineer in Microsoft.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: