I have created a function to add one user at a time into particular group (Administrators etc) but it seems to be taking too long to respond on GroupPrinciple(5-10 seconds) and group.members.add(5-10 seconds) call and slowing down my app, it takes almost 15-20 sec to respond, is there a faster way to do this?
private static void Add()
{
var userContext = new PrincipalContext(ContextType.Domain);
var user = new UserPrincipal(userContext);
user.SamAccountName = "c1111111";
var searcher = new PrincipalSearcher(user);
user = searcher.FindOne() as UserPrincipal;
var machineContext = new PrincipalContext(ContextType.Machine, "ABCDEFGHI1",
null, ContextOptions.Negotiate, "c123789", "test123");
var group = GroupPrincipal.FindByIdentity(machineContext,"Administrators");
group.Members.Add(user);
Console.WriteLine("saving group");
group.Save();
}