Beispiel #1
0
        public static PSADGroup ToPSADGroup(this ADGroup group)
        {
            var adGroup = new PSADGroup()
            {
                DisplayName     = group.DisplayName,
                SecurityEnabled = group.SecurityEnabled,
                MailNickname    = group.Mail
            };

            return((PSADGroup)AssignObjectId(adGroup, group.ObjectId));
        }
        public IEnumerable <PSADGroup> FilterGroups(ADObjectFilterOptions options, ulong first = ulong.MaxValue, ulong skip = 0)
        {
            if (!string.IsNullOrEmpty(options.Id))
            {
                try
                {
                    // use GetObjectsByObjectId to handle Redirects in the CSP scenario
                    PSADGroup group = this.GetObjectsByObjectId(new List <string> {
                        options.Id
                    }).FirstOrDefault() as PSADGroup;
                    if (group != null)
                    {
                        return(new List <PSADGroup> {
                            group
                        });
                    }
                }
                catch { /* The group does not exist, ignore the exception */ }
            }
            else
            {
                Rest.Azure.OData.ODataQuery <ADGroup> odataQuery = null;
                if (options.Mail != null)
                {
                    odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.Mail == options.Mail);
                }
                else
                {
                    if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
                    {
                        options.SearchString = options.SearchString.TrimEnd('*');
                        odataQuery           = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.DisplayName.StartsWith(options.SearchString));
                    }
                    else
                    {
                        odataQuery = new Rest.Azure.OData.ODataQuery <ADGroup>(g => g.DisplayName == options.SearchString);
                    }
                }

                return(new GenericPageEnumerable <ADGroup>(
                           delegate()
                {
                    return GraphClient.Groups.List(odataQuery);
                }, GraphClient.Groups.ListNext, first, skip).Select(g => g.ToPSADGroup()));
            }

            return(new List <PSADGroup>());
        }