Powershell - Remove-DistributionGroupMember: A parameter cannot be found that matches parameter name 'Member'

Juan Cabrera Jamoulle 40 Reputation points
2023-02-08T14:48:26.9233333+00:00

Hi, I get this error when trying to remove members in a distribution group with a PowerShell script

…   Remove-DistributionGroupMember -Identity $GroupName -Member $_ -Con …     |                                                          ~~~~~~~     | A parameter cannot be found that matches parameter name 'Member'.

The code to remove is this

        $Members_To_Remove |
        foreach {
            if ( !$DryRun ) {
                Remove-DistributionGroupMember -Identity $GroupName -Member $_ -Confirm:$false
            }
            Write-Host -ForegroundColor red "$_ User removed in Distribution Group $Grupname"
        }
    }

The code to add works fine, I can add members.

        $Members_To_Add |
        foreach {
            if ( !$DryRun ) {
                Add-DistributionGroupMember -Identity "$GroupName" -Member $_
            }
            Write-Host -ForegroundColor green "Added User $_ in $GroupName as Member"
        }

It seems that the parameter member is not in the remove command

get-command -name Remove-DistributionGroupMember | Fl *

HelpUri             : https://docs.microsoft.com/powershell/module/exchange/remove-distributiongroupmember
ScriptBlock         : 
                          [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')]
                          param(
                          
                          [Parameter(ParameterSetName='Identity', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
                          ${Identity}
                          )
                          Begin {
                              $CmdletRequestId = [System.Guid]::NewGuid().ToString()
                          ....

But it is in add command

HelpUri             : https://docs.microsoft.com/powershell/module/exchange/add-distributiongroupmember
ScriptBlock         : 
                          [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')]
                          param(
                          
                          [Parameter(ParameterSetName='Identity', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
                          ${Identity},
                      
                          [Parameter(ValueFromPipeline=$true)]
                          [ValidateNotNull()]
                          ${Member}                         #<----- Here
                          )
                          Begin {
                              $CmdletRequestId = [System.Guid]::NewGuid().ToString()
                          ....

could it be related to a permission problem?

Juan

Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,349 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,446 questions
{count} votes

Accepted answer
  1. Aholic Liang-MSFT 13,826 Reputation points Microsoft Vendor
    2023-02-13T09:18:33.69+00:00

    Hi,

    Please run the following command to get all the permissions of the specified user:

    Get-ManagementRoleAssignment -RoleAssignee administrator@contoso.com -Delegati
    t-Table -Auto Role,RoleAssigneeName,RoleAssigneeType
    

    Then, compare with the permissions required by the remove command below to see if anything is missing.

    2023-2-10-1

    In addition , I am wondering if you could remove members of distribution groups in the EAC ?

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 45,596 Reputation points
    2023-02-08T15:57:11.3233333+00:00

    Yes, it could be related to the RBAC role your user account holds in the Exchange organization. But that's related to Exchange, not PowerShell.