Adding a group to another Group.

Asked By Ryan Gomez
20-Nov-09 09:15 AM
Earn up to 30 extra points for answering this tough question.

Hi everyone,

I'm attempting to add an existing group to another group in AD as shown below. However, I keep an exception when I attempt to do so.

I've been Googling about but I can't seem to find (if any) references to adding groups to other groups. Is this possible with .NET? Any pointers would be greatly appreciated. Thanks.


var groupPathA = "LDAP://CN=" + groupName + ",OU=ou1,DC=*****,DC=******,DC=***";
            var groupA = new DirectoryEntry(groupPathA, username, password, AuthenticationTypes.Secure);

            var grouppathB = "LDAP://CN=item,OU=ou2,OU=ou1,DC=*****,DC=*****,DC=***";
            vargroupB = new DirectoryEntry(groupPathB, username, password, AuthenticationTypes.Secure);
            
            group.RefreshCache();
            using (groupA)
            {
                try
                {
                     groupA.Invoke("Add", new[] { groupB.Path });
                }
                catch (Exception ex)
                {
                   Console.WriteLine(ex.ToString());
                 }
             }

Create New Account