
Scenario
Recently we did a google suite to Microsoft 365 migration, there were around 700 Google groups which we need to add as Microsoft 365 groups. We have created all groups using PowerShell script and added all the users using the same script. During testing we got the details that there were users who were not added to the security groups. So we have written a PowerShell script for adding missing users to the respective groups.
Adding Users M365 Groups using PowerShell
We created the csv file where we have all the Microsoft 365 Group alias names and added users in Owner and Member columns. In PowerShell cmdlet, we have exported the PowerShell and executed the below script function to add users to relevant roles in M365 groups.
function UpdateM365GroupPermissions($Groupalias, $Owners, $Members)
{
$Groupalias = $Groupalias
$arrOwners = $Owners.split(',')
$arrMembers = $Members.split(',')
write-host 'Owners: ' $arrOwners
write-host 'Members: ' $arrMembers
Write-Host 'Updateing Group permissions: ' $Groupalias
Add-PnPMicrosoft365GroupOwner -Identity $Groupalias -Users $arrOwners
Add-PnPMicrosoft365GroupMember -Identity $Groupalias -Users $arrMembers
Write-Host 'Updated Group permissions' -ForegroundColor Green
}
No Comments