Active Directory User Group Memberships GroupPrincipal

前端 未结 2 1749
醉酒成梦
醉酒成梦 2021-01-05 10:19

I am trying to use GroupPrincipal (part of the System.DirectoryServices.AccountManagement namespace) to populate a list of type string, so I can ch

2条回答
  •  旧巷少年郎
    2021-01-05 10:40

    I think you have a simple typo in your method - you're getting the group principal into SearchGroup (check for NULL, btw!!) and then you're grabbing the members off GroupName ??

    Try this:

    private void populateGroups()
    {
        GroupPrincipal SearchGroup = GroupPrincipal.FindByIdentity(context, "Group Name");
    
        if(SearchGroup != null)
        {
           GroupName = new List();
    
           // call 'GetMembers' on 'SearchGroup' here!! 
           foreach (UserPrincipal p in SearchGroup.GetMembers())  
           {
              GroupName.add(p.SamAccountName);
           }
        }
    }
    

提交回复
热议问题