获取Active Directory的成员(递归)不会返回域用户

我尝试读取Active Directory中特定组的所有用户。只要我的特定组内没有广告默认组,该代码就可以正常工作。例如,我有一个Billing * ...组,该组包含Domain-Users。 GetMembers函数应返回所有用户,但仅返回3XX的3个。

如果特定组中没有默认组,则该代码已在生产中,并且可以正常运行。

            try
            {

                using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
                using (GroupPrincipal pg = new GroupPrincipal(context) { Name = "Billing*" })
                using (PrincipalSearcher searcher = new PrincipalSearcher(pg))
                {


                    var col = searcher.FindAll();
                    if (col == null)
                        return;
                    foreach (GroupPrincipal GrpPrncpl in col)
                    {

                        GroupPrincipal g = (GroupPrincipal)GrpPrncpl;
                        if (GrpPrncpl == null || GrpPrncpl.GetType() != typeof(GroupPrincipal)) return; //continue in Parallel.Foreach

                        try
                        {
                            PrincipalSearchResult<Principal> Members = g.GetMembers(true);
                            foreach (Principal member in Members)
                            {
                                ADContentElementMembership mem = new ADContentElementMembership
                                {
                                    groupGUID = NNToString(GrpPrncpl.Guid),
                                    memberGUID = NNToString(member.Guid),
                                };
                                adcemember.TryAdd(mem, 0 /*irrelevantes byte als value*/);
                            }
                        }
                        catch (PrincipalOperationException e)
                        {
                            Log.Info("Cross Store Reference",e);
                        }
                    }
                }
                Log.Debug("End AD Get Members");
            }
            catch (Exception e)
            {
                string fehler = "Error on reading AD members";
                Log.Error(fehler, e);
            }

如何获得默认组的用户?

评论