I've been tasked with creating a solution to add and remove AD users to and from AD groups. The following code is functional, except when I try to save the group. I'm getting an exception of "The object already exists." I've narrowed down the issue (I think) to the SamAccountName, and I think that is what is causing the exception.
I don't have access to modify anything in AD aside from the permissions I've been granted to modify the groups designated to have users added/removed from them. I've done endless research, and I just haven't been able to determine a solution. Any help would be deeply appreciated. Thanks in advance.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "address", "DN", "username", "password");
GroupPrincipal grp = new GroupPrincipal(ctx, sGroup);
UserPrincipal usr = UserPrincipal.FindByIdentity(ctx, sUser);
if (grp != null)
{
grp.Members.Add(usr);
grp.Save();
}