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 Exchange Server Management
Exchange Hybrid management
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kael Yao 37,746 Reputation points Moderator
    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.