Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete user in active directory using c#

I've written some code but not works it throws Exception "An operations error occurred." code --->

DirectoryEntry dirEntry = new DirectoryEntry("LDAP path", "admin-username", "admin-password");
dirEntry.Properties["member"].Remove("username-delete");
dirEntry.CommitChanges();
dirEntry.Close();

give me some ideas to get out of this things..

like image 258
soundy Avatar asked Feb 24 '12 05:02

soundy


People also ask

How do I remove a user from Active Directory?

1) To delete an Active directory domain user account, open the Active Directory Users and Computers MMC snap-in, right click the user object and select “Delete” from the context menu. Click “Yes” is the dialog box “Are you sure you want to delete this object?” to confirm the deletion.

How do I remove a user from a powershell ad?

The Remove-ADUser cmdlet removes an Active Directory user. The Identity parameter specifies the Active Directory user to remove. You can identify a user by its distinguished name (DN), GUID, security identifier (SID), or Security Account Manager (SAM) account name.

What happens when you delete a user from Active Directory?

When you delete Active Directory/LDAP user accounts in Active Directory/LDAP, those user accounts remain on the Users page in the Admin Portal but they can no longer access CyberArk Identity Connector.


1 Answers

When you are already using a DirectoryEntry there is no need for PrincipalContext or UserPrincipal.

You can simply use the DeleteTree() method:

DirectoryEntry dirEntry = new DirectoryEntry("LDAP path", "admin-username", "admin-password");
dirEntry.DeleteTree();
like image 143
Norman Avatar answered Oct 04 '22 03:10

Norman