0
votes

I am trying to add a bulk of users from a CSV file to a MsolGroup via PowerShell. I have only the username of the users. (User.name) This is what I tried:

1. Read the CSV file with the userName and get the Msol user object from it:

$group | % {Get-MsolUser -UserPrincipalName $_.name}

2. Add these ObjectID's to the requested MsolGroup:

$group | % {Get-MsolUser -UserPrincipalName $_.name} | % {Add-MsolGroupMember -GroupObjectId 86bbcf6b-feb6-4fe3-a9db-eb1e0b81ed55 -GroupMemberObjectId $_.objectid

This is the Error I get:

Add-MsolGroupMember : You cannot update mail-enabled groups using this cmdlet. Use Exchange Online to perform this operation.

Is there a better way to do it? What am I doing wrong?

2

2 Answers

0
votes

As noted in the error message, this cmdlet will only work against "regular" security groups. For mail-enabled security groups, use the Exchange remote PowerShell and Add-DistributionGroupMember

Refer documentation

0
votes

We could use

$group | % {Get-MsolUser -UserPrincipalName $.name} | % {Add-DistributionGroupMember -Identity "86bbcf6b-feb6-4fe3-a9db-eb1e0b81ed55" -Member $.objectid