I have written the code, which works fine when I try to remove a user.
try
{
Console.WriteLine("user name is " + args[0]);
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, args[0]);
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "Administrators");
if (user != null && group != null)
{
try
{
if (group.Members.Remove(user))
{
Console.WriteLine("User successfully removed from Local Administrators.");
}
else
{
Console.WriteLine("User is not a Local Administrator.");
}
}
catch
{
Console.WriteLine("User is not a Local Administrator.");
}
}
else
{
Console.WriteLine("User was not found.");
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
But it prints user not found when I try for a domain account.
T1/test1 is a domain account.
If I create a user and make it administrator. and I am able to remove it.

I think you have to change your context depending on the type of user (local or domain). I cannot test this code because I am not connected to a domain, but hope it should help you: