0

我正在尝试使用 AccountManagement 将帐户添加到安全组。我能够找到帐户(组主体) sid ,但是在尝试将其添加到管理员时抛出错误。

枚举组成员身份时发生错误 (1332)。无法解析成员的 SID

   using( var machine_principal = new PrincipalContext(ContextType.Machine, server1))
           {
               try
               {                 
                    using (var oPrincipalContext = new PrincipalContext(ContextType.Domain,"xx.com"))
                    {
                        GroupPrincipal use = new GroupPrincipal(oPrincipalContext);
                        GroupPrincipal group = new GroupPrincipal(machine_principal);
                      group = GroupPrincipal.FindByIdentity(machine_principal, "Administrators");
                        use = GroupPrincipal.FindByIdentity(oPrincipalContext, IdentityType.SamAccountName, "myname");//Able to find group and sid
                         group.Members.Add(oPrinicpipalContext,IdentityType.SamAccountName,use.SamAccountName);//_Throwing exception -the member's Sid could not be resolved_

                    }
               }
            catch (Exception ed)
            {
                MessageBox.Show(ed.Message);
            };
           };
4

0 回答 0