Click here to Skip to main content
14,545,215 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello everybody,

Is there a way to set multiple groups in Active Directory ?

For example :

What I have tried:
string group = "User02"; 
DirectoryEntry grp;
grp = aduser.Children.Find($"CN={group},OU=Gruppen,OU=FIR", "group")
grp = aduser.Children.Add(group, "group");
Updated 25-May-20 2:14am
Richard Deeming 19-May-20 12:47pm
You have already posted this in the ASP.NET forum:
How do I multiple group in Active Directory ? - ASP.NET Discussion Boards[^]
Rate this:
Please Sign up or sign in to vote.

Solution 1

You add them one a time.

It doesn't matter if you're adding a group to a bunch of groups, or adding a bunch of groups to a single group. You add them one at a time.
ugurarslanm 19-May-20 13:25pm
Thx and What is the Solution ?
I want to add multiple groups.

For example :
In my project, when I have selected the Checkbox, the user must be created with multiple groups

string group1
string group2
string group3
Dave Kreskowiak 19-May-20 15:31pm
You already have the solution. You do what you're doing for one group for each of the groups you want to add.
Rate this:
Please Sign up or sign in to vote.

Solution 2

List<string> groupToAdd = new List<string>();

foreach(var group_ in groupToAdd)
     var grp = aduser.Children.Find($"CN={group_},OU=XXX,OU=XXX", "group");
     if (grp != null)                    
         grp.Invoke("Add", new object[] { newUser.Path.ToString() });

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100