GroupPrincipal.GetMembers fails when group (or child group if recursive) contains ForeignSecurityPrincipal

前端 未结 3 827
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 09:53

This is not so much a question as information for anyone experiencing the same problem.

The following error occurs:

System.Directory         


        
3条回答
  •  日久生厌
    2021-01-04 10:08

    Sure this is an old thread, but might help someone. I used the below code block the solve the problem. the Principal class exposes a property called StructuralObjectClass which tells you what is the AD Class of that principal. I used this to decide whether the object is a user. The GetMembers(true) recursively searches all nested-members in the groupPrincipal in question.

    Hope this helps someone.

        List members = new List();
        foreach (var principal in groupPrincipal.GetMembers(true))
        {
            var type = principal.StructuralObjectClass;
            if (type.Contains("user"))
                members.Add((UserPrincipal)principal);
        }
    

    Thanks, R

提交回复
热议问题