I\'ve written some code but not works it throws Exception \"An operations error occurred.\" code --->
DirectoryEntry dirEntry = new DirectoryEntry(\"LDAP pat
If you're on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement
(S.DS.AM) namespace. Read all about it here:
Basically, you can define a domain context and easily find users and/or groups in AD:
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find the user you want to delete
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");
if(user != null)
{
user.Delete();
}
The new S.DS.AM makes it really easy to play around with users and groups in AD!
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();