예제 #1
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);
                }
            });
        }