Там решение:
public static ArrayList GetUserGroupsExcludingPrimaryGroup(string sUserName)
{
ArrayList myItems = new ArrayList();
UserPrincipalEx oUserPrincipal = GetUser(sUserName);
var objectSid = oUserPrincipal.ObjectSid.ToString();
objectSid = objectSid.Substring(0, objectSid.LastIndexOf("-")) + "-" + oUserPrincipal.PrimaryGroupID;
PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();
foreach (Principal oResult in oPrincipalSearchResult)
{
if (objectSid != oResult.Sid.ToString())
myItems.Add(oResult.Name);
}
return myItems;
}
AccountManagement - переопределить
namespace System.DirectoryServices.AccountManagement
{
[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("User")]
public class UserPrincipalEx : UserPrincipal
{
public UserPrincipalEx(PrincipalContext context) : base(context) { }
public UserPrincipalEx(PrincipalContext context, string samAccountName, string password, bool enabled) : base(context, samAccountName, password, enabled) { }
...
[DirectoryProperty("primaryGroupID")]
public Int32 PrimaryGroupID
{
get { return (Int32)ExtensionGet("primaryGroupID")[0]; }
set { ExtensionSet("primaryGroupID", value); }
}
[DirectoryProperty("objectSid")]
public SecurityIdentifier ObjectSid
{
get { return new SecurityIdentifier((byte[])ExtensionGet("objectSid")[0], 0); }
set { ExtensionSet("objectSid", value); }
}
}
}