Add Member to Mail Enabled Security Group via PowerShell

Shiv bhushan Tomar 1 Reputation point
2022-04-25T13:35:11.567+00:00

I am using PowerShell script to add memebr in an Mail Enabled security group:
after connecting to ExchangeOnlineManagement, using the below script to add member which is working fine for Distribution list but for Mail Enabled Security Group it throws an exception:

exception: "System.Management.Automation.RemoteException: You don't have sufficient permissions. This operation can only be performed by a manager of the group."

and If I add the parameter "-BypassSecurityGroupManagerCheck" it throws an exception :

exception: "Parameter -BypassSecurityGroupManagerCheck doest not match."

Script:

$group = Get-DistributionGroup -Identity $groupName

if($null -ne $group)
{
    Add-DistributionGroupMember -Identity $groupName -Member $userEmail -Confirm:$false  

}  

`

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,481 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
1,985 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kael Yao-MSFT 37,676 Reputation points Microsoft Vendor
    2022-04-27T01:44:23.997+00:00

    Hi @Shiv bhushan Tomar

    The cause of this issue may be the account you are using to run the script doesn't have the required permission.

    If this account isn't the owner of the security group, in order to use the parameter BypassSecurityGroupManagerCheck to add members to this security group, the account must be assigned Security Group Creation and Membership role.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.