public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (this.IsParameterBound(c => c.GroupObject))
                {
                    GroupObjectId = GroupObject.Id;
                }
                else if (this.IsParameterBound(c => c.GroupDisplayName))
                {
                    var targetGroup = ActiveDirectoryClient.GetGroupByDisplayName(GroupDisplayName);
                    GroupObjectId   = targetGroup.Id;
                }

                ADObjectFilterOptions options = new ADObjectFilterOptions
                {
                    Id     = GroupObjectId,
                    Paging = true
                };

                PSADObject group = ActiveDirectoryClient.FilterGroups(options).FirstOrDefault();
                if (group == null)
                {
                    throw new KeyNotFoundException(string.Format(ProjectResources.GroupDoesntExist, GroupObjectId));
                }

                ulong first = MyInvocation.BoundParameters.ContainsKey("First") ? this.PagingParameters.First : ulong.MaxValue;
                ulong skip  = MyInvocation.BoundParameters.ContainsKey("Skip") ? this.PagingParameters.Skip : 0;
                WriteObject(ActiveDirectoryClient.GetGroupMembers(options, first, skip), true);
            });
        }
        public List <PSADObject> ListUserGroups(string principal)
        {
            List <PSADObject> result   = new List <PSADObject>();
            string            objectId = GetObjectId(new ADObjectFilterOptions {
                UPN = principal
            });
            PSADObject user = GetADObject(new ADObjectFilterOptions {
                Id = objectId.ToString()
            });
            var groupsIds    = GraphClient.Users.GetMemberGroups(objectId.ToString(), new UserGetMemberGroupsParameters());
            var groupsResult = GraphClient.Objects.GetObjectsByObjectIds(new GetObjectsParameters {
                ObjectIds = groupsIds.ToList()
            });

            result.AddRange(groupsResult.Select(g => g.ToPSADGroup()));
            return(result);
        }
        public string GetObjectId(ADObjectFilterOptions options)
        {
            if (options != null && options.Id != null)
            {
                return(options.Id);
            }
            else
            {
                PSADObject adObj = GetADObject(options);

                if (adObj == null)
                {
                    throw new KeyNotFoundException("The provided information does not map to an AD object id.");
                }

                return(adObj.Id);
            }
        }
Exemple #4
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                ADObjectFilterOptions options = new ADObjectFilterOptions
                {
                    Id     = GroupObjectId == Guid.Empty ? null : GroupObjectId.ToString(),
                    Paging = true
                };

                PSADObject group = ActiveDirectoryClient.FilterGroups(options).FirstOrDefault();
                if (group == null)
                {
                    throw new KeyNotFoundException(string.Format(ProjectResources.GroupDoesntExist, GroupObjectId));
                }

                do
                {
                    WriteObject(ActiveDirectoryClient.GetGroupMembers(options), true);
                } while (!string.IsNullOrEmpty(options.NextLink));
            });
        }
        public PSADObject GetADObject(ADObjectFilterOptions options)
        {
            PSADObject result = null;

            Debug.Assert(options != null);
            if (IsSet(options.Mail, options.UPN, options.Id))
            {
                result = FilterUsers(options).FirstOrDefault();
            }

            if (result == null && IsSet(options.SPN, options.Id))
            {
                result = FilterServicePrincipals(options).FirstOrDefault();
            }

            if (result == null && IsSet(options.Mail, options.Id))
            {
                result = FilterGroups(options).FirstOrDefault();
            }

            return(result);
        }