コード例 #1
0
        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);
            });
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (this.IsParameterBound(c => c.InputObject))
                {
                    ObjectId = InputObject.Id;
                }
                else if (this.IsParameterBound(c => c.DisplayName))
                {
                    var group = ActiveDirectoryClient.GetGroupByDisplayName(DisplayName);
                    ObjectId  = group.Id;
                }

                ConfirmAction(
                    Force.IsPresent,
                    string.Format(ProjectResources.RemoveGroupConfirmation, ObjectId),
                    ProjectResources.RemovingGroup,
                    ObjectId.ToString(),
                    () => ActiveDirectoryClient.RemoveGroup(ObjectId.ToString()));

                if (PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            });
        }
コード例 #3
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (this.IsParameterBound(c => c.TargetGroupObject))
                {
                    TargetGroupObjectId = TargetGroupObject.Id;
                }
                else if (this.IsParameterBound(c => c.TargetGroupDisplayName))
                {
                    var targetGroup     = ActiveDirectoryClient.GetGroupByDisplayName(TargetGroupDisplayName);
                    TargetGroupObjectId = targetGroup.Id;
                }

                if (this.IsParameterBound(c => c.MemberUserPrincipalName))
                {
                    var memberObjectId = new List <Guid>();
                    foreach (var memberUPN in MemberUserPrincipalName)
                    {
                        memberObjectId.Add(ActiveDirectoryClient.GetObjectIdFromUPN(memberUPN));
                    }

                    MemberObjectId = memberObjectId.ToArray();
                }

                foreach (var memberObjectId in MemberObjectId)
                {
                    var groupAddMemberParams = new GroupAddMemberParameters()
                    {
                        Url = string.Format("{0}/{1}/directoryObjects/{2}",
                                            AzureEnvironmentConstants.AzureGraphEndpoint,
                                            AzureRmProfileProvider.Instance.Profile.DefaultContext.Tenant,
                                            memberObjectId)
                    };

                    if (ShouldProcess(target: memberObjectId.ToString(), action: string.Format("Adding user with object id '{0}' to group with object id '{1}'.", memberObjectId, TargetGroupObjectId)))
                    {
                        ActiveDirectoryClient.AddGroupMember(TargetGroupObjectId.ToString(), groupAddMemberParams);
                    }
                }

                if (PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            });
        }
コード例 #4
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (this.IsParameterBound(c => c.GroupObject))
                {
                    GroupObjectId = GroupObject.Id;
                }
                else if (this.IsParameterBound(c => c.GroupDisplayName))
                {
                    var group     = ActiveDirectoryClient.GetGroupByDisplayName(GroupDisplayName);
                    GroupObjectId = group.Id;
                }

                if (this.IsParameterBound(c => c.MemberUserPrincipalName))
                {
                    var memberObjectId = new List <Guid>();
                    foreach (var memberUPN in MemberUserPrincipalName)
                    {
                        memberObjectId.Add(ActiveDirectoryClient.GetObjectIdFromUPN(memberUPN));
                    }

                    MemberObjectId = memberObjectId.ToArray();
                }

                foreach (var memberObjectId in MemberObjectId)
                {
                    if (ShouldProcess(target: memberObjectId.ToString(), action: string.Format("Removing user with object id '{0}' from group with object id '{1}'.", memberObjectId, GroupObjectId)))
                    {
                        ActiveDirectoryClient.RemoveGroupMember(GroupObjectId.ToString(), memberObjectId.ToString());
                    }
                }

                if (PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            });
        }