Question

Comment puis-je obtenir tous les groupes de Paramètres des membres?Méthode GetGroups Renvoyer un membre de + groupe principal.

public static ArrayList GetUserGroups(string sUserName)
{
    ArrayList myItems = new ArrayList();
    UserPrincipal oUserPrincipal = GetUser(sUserName);

    PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();

    foreach (Principal oResult in oPrincipalSearchResult)
    {
        if(NOT_PRIMARY) // <-- check by primary group ID? 
                        // How get group GUID/ CID by ID ?
            myItems.Add(oResult.Name);
    }
    return myItems;
}

Était-ce utile?

La solution

Il y a une solution:

    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;
    }

CompteManagement - Remplacement

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); }
        }

    }
}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top