0
Reply

Delete security group in Active Directory

Bonnie Smith

Bonnie Smith

Apr 26 2010 10:53 AM
3.6k
I have to delete a group from Active Directory. I have create & list users working correctly and have tried many different instances of deleting group, but none have worked.  Here is my current c# code, where "path" is a string read from settings.xml successfully:

public StatusObject DeleteADGroup(string user_id, string groupName, string password, string domain){

StatusObject status = new StatusObject(ClassName);
sting domainAndUserName = domain + @"\" + user_id;

if(DoesGroupExist(groupName)){
try{
DirectoryEntry entry = new DirectoryEntry("LDAP://" + path, domainAndUserName, password);
DirectoryEntry group = entry.Children.Find("CN=" + groupName, "group");
entry.Children.Remove(group);
group.CommitChanges();
status.Successful = true;

catch(Exception ex) {
// log error handling
}
else{
status.Successful = false;
//false handling
}
return status;
}

Any suggestions or help would be greatly appreciated!  I've been working on this for what seems like an eternity!!  Thank you!

blskv