Link to home
Start Free TrialLog in
Avatar of centem
centemFlag for United States of America

asked on

Adding to AD group with ASP and AccountManagement namespace

Greetings,
I wan to use the following code as a template to add user to a particular group in AD. The problem I'm encountering is how to add to an OU group that has the same name as others. For example, Users in Miami in Florida in US versus Users in Madrid in Spain. Thanks.
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx,
                                                   IdentityType.Name,
                                                   "Domain Admins");
if (grp != null)
{
    grp.Members.Remove(ctx, IdentityType.Name, "John Smith");          
    grp.Members.Add(ctx, IdentityType.Name, "Jim Daly");
    grp.Save();
    grp.Dispose();
}
ctx.Dispose();



ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of centem

ASKER

That was extremely helpful. Thank you. I'm going to experiment a bit and let you know. Thanks
Glad it made sense to you,  reads like gobbeldygook to me.
Avatar of centem

ASKER

Not just helpful but also educational. Value added info.