troubleshooting Question

Powershell script to grant send on behalf permissions from one array of mailboxes to another in exchange

Avatar of Lee Parker
Lee ParkerFlag for United Kingdom of Great Britain and Northern Ireland asked on
PowershellExchange* pnppowershell
4 Comments1 Solution5 ViewsLast Modified:
First time post so if I have done anything wrong here let me know!

In office 365/exchange online I have the task of providing one list of mailboxes send on behalf permissions to each member of the 2nd list. So far I have a very simple script that looks like:

#arr1 mailboxes 
#arr2 send on behalf access permissions to arr1 mailboxes

$arr1 = 'ab', cd'
$arr2 = 'ef', 'gh'

ForEach($i in $arr1){
    ForEach($j in $arr2){
        Set-Mailbox -identity "$i" -GrantSendOnBehalfTo "$j"


Open in new window

The problem here is that 'gh' has send on behalf permissions to 'ab' and 'gh' but 'ef' does not!

Looks like my logic is wrong as the final item in arr2 gets the send on behalf permission but the rest do not. How do I give all items in the 2nd array send on behalf permissions and not just the last one?

**update** Logic is fine. What is happening is exchange is replacing the permissions so as 'ef' is granted access to 'ab', when powershell iterates over to to 'gh' it overrides the permissions 'ef' already had, resulting in 'gh' having send on behalf permissions only...
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros