Both the working and failing targets are machines in the same domain. Code is down below. When I use it against some machines in my domain, I get a System.DirectoryServices.AccountManagement.PrincipalOperationException with a message: "While trying to retrieve the authorization groups, an error (1332) occurred." The error is thrown by GetAuthorizationGroups().
Note: The username I use to connect is a local admin to the machine in both cases.
PrincipalContext ctx = new PrincipalContext(ContextType.Machine, machineName, domainname + "\\" + adminusername, pass);
List<Principal> retList = new List<Principal>();
using (var user = UserPrincipal.FindByIdentity(ctx, probedusername))
{
if (user != null)
{
PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups();
foreach (Principal group in groups)
{
retList.Add(group);
}
}
}