How to assign a Role to multiple users in Exchange Online
Introduction
This script is used to help administrator to query current role assignment policies and assign the selected policy to multiple mailboxes.
Scenarios
This script is used to help administrator to query current role assignment policies and assign the selected policy to multiple mailboxes.
Script
You can use this script in the following way.
1. Open Windows PowerShell.
2. Type the script path at the Windows PowerShell Console.
For example, type C:\Script\ ChangeRoleAssignmentEXO
Here are some code snippets for your reference.
PowerShellEdit|Removepowershellif($userOrgChoice -eq $($policy.count )) { $mailboxlist = Get-Mailbox foreach($mailbox in $mailboxlist) { Set-Mailbox $mailbox.PrimarySmtpAddress -RoleAssignmentPolicy $Policy[$usernewChoice].Name } } elseif(($userOrgChoice -le $Policy.Count) -and ($usernewChoice -le $Policy.Count)) { $mailboxlist = Get-Mailbox | Where { $_.RoleAssignmentPolicy -Eq $Policy[$userOrgChoice].Name } foreach($mailbox in $mailboxlist) { Set-Mailbox $mailbox.PrimarySmtpAddress -RoleAssignmentPolicy $Policy[$usernewChoice].Name } } else { Write-Host "Please input a valid selection" }if($userOrgChoice -eq $($policy.count )) { $mailboxlist = Get-Mailbox foreach($mailbox in $mailboxlist) { Set-Mailbox $mailbox.PrimarySmtpAddress -RoleAssignmentPolicy $Policy[$usernewChoice].Name } } elseif(($userOrgChoice -le $Policy.Count) -and ($usernewChoice -le $Policy.Count)) { $mailboxlist = Get-Mailbox | Where { $_.RoleAssignmentPolicy -Eq $Policy[$userOrgChoice].Name } foreach($mailbox in $mailboxlist) { Set-Mailbox $mailbox.PrimarySmtpAddress -RoleAssignmentPolicy $Policy[$usernewChoice].Name } } else { Write-Host "Please input a valid selection" }
Examples
Example1: Change the mailboxes’ role assignment policy from ‘Default’ to ‘Limited’.
ChangeRoleAssignmentEXO.ps1 -Credential $Cred
![]()
Result Screenshot:

Prerequisites
Exchange Online
Windows PowerShell 2.0