2016-10-20 6 views
1

Frage: Wie lösche ich eine Gruppe aus dem Active Directory?So löschen Sie AD-Gruppe


Was habe ich versucht:

1. PrinipalContext

Ich versuche, eine Active Directory-Gruppe zu löschen. Ich habe dieses Recht jetzt:

using (var ctx = new PrincipalContext(ContextType.Domain, myDomain, ldapUser, ldapPassword)) 
{ 
    var group1 = new GroupPrincipal(ctx, groupName); 
    group1.Delete(); 
} 

Aber ich erhalte eine Fehlermeldung: "Unpersisted Principal objects can not be deleted."

Das hat mich führen here, aber ich weiß nicht, was die invoke Magie dreht sie alles um, und es macht mir Angst ein wenig.

2. Directory

http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#33

Aber ich habe einfach "The server is not operational" Fehler bekommen.

Ich muss nur die AD-Gruppe löschen, ist es überhaupt möglich?

Antwort

0

Es stellt sich heraus, dass die DirectoryEntry funktioniert, aber meine ldap URLs waren falsch. Hier ist der Code, den ich am Ende mit:

using (var ou = new DirectoryEntry(ouPath, ldapUser, ldapPassword)) 
{ 
    using (var group = new DirectoryEntry(groupPath, ldapUser, ldapPassword)) 
    { 
      ou.Children.Remove(group); 
      group.CommitChanges(); 
    } 
} 

FALSCH Altwerte

ouPathLDAP://myDomain.local/OU=myTier1,DC=myDomain,DC=local

GroupPathLDAP://groupname/OU=myTier3,OU=myTier2,OU=myTier1,DC=myDomain,DC=local

RICHTIG neue Werte

ouPathLDAP://myDomain.local/OU=myTier2,OU=myTier1,DC=myDomain,DC=local

GroupPathLDAP://myDomain.local/CN=groupName,OU=myTier3,OU=myTier2,OU=myTier1,DC=myDomain,DC=local