Categories: ExchangePowerShell

Exchange 2013 – Grant SendOnBehalf permission for Mailbox overwrites Existing permissions

Changing Send On Behalf setting in Exchange 2010 / Exchange 2013 or Exchange 2016 is quite simple task that can be easily done from GUI. It gets a bit more complicated when you try to add/change Send On Behalf rights from PowerShell.

Problem Description

Usually most people will go for

Set-Mailbox <UserToAddPermissionsTo> -GrantSendOnBehalf <UserToGivePermissionsTo>

It's a simple command but it actually does a very dangerous thing… it overwrites current GrantSendOnBehalf permissions. While it's not a problem when it's first time you set it up, it's a big deal when there are already multiple people added to GrantSendOnBehalf field.

Solution

Fortunately there's a simple way to do this to not overwrite this setting. Below you can find couple of commands that should make your life simpler.

function Add-DistributionListGrantSendOnBehalfTo { Param($newTrustee, $targetDistributionGroup)
    Set-DistributionGroup $targetDistributionGroup -GrantSendOnBehalfTo @{add=$newTrustee}
}
function Remove-DistributionListGrantSendOnBehalfTo { Param($oldTrustee, $targetDistributionGroup)
    Set-DistributionGroup $targetDistributionGroup -GrantSendOnBehalfTo @{remove=$oldTrustee}
}
function Replace-DistributionListGrantSendOnBehalfTo { Param($oldTrustee, $newTrustee, $targetDistributionGroup)
    Set-DistributionGroup $targetDistributionGroup -GrantSendOnBehalfTo @{add=$newTrustee}
    Set-DistributionGroup $targetDistributionGroup -GrantSendOnBehalfTo @{remove=$oldTrustee}
}
function Remove-MailboxGrantSendOnBehalfTo { Param($oldTrustee, $targetMailbox)
    Set-Mailbox $targetMailbox -GrantSendOnBehalfTo @{remove=$oldTrustee}
}
function Add-MailboxGrantSendOnBehalfTo { Param($newTrustee, $targetMailbox)
    Set-Mailbox $targetMailbox -GrantSendOnBehalfTo @{add=$newTrustee}
}
function Replace-MailboxGrantSendOnBehalfTo { Param($oldTrustee, $newTrustee, $targetMailbox) 
    Set-Mailbox $targetMailbox -GrantSendOnBehalfTo @{remove=$oldTrustee}
    Set-Mailbox $targetMailbox -GrantSendOnBehalfTo @{add=$newTrustee}
}

Simple usage of Exchange PowerShell commands from above:

Add-MailboxGrantSendOnBehalfTo -NewTrustee <AllowedUserToSendOnBehalf> -TargetMailbox <UserMailboxToManage>

Replace-MailboxGrantSendOnBehalfTo -NewTrustee <AllowedUserToSendOnBehalf> -OldTrustee <ReplacedUserToSendOnBehalf> -TargetMailbox <UserMailboxToManage>

Remove-MailboxGrantSendOnBehalfTo -OldTrustee <ReplacedUserToSendOnBehalf> -TargetMailbox <UserMailboxToManage>

This post was last modified on April 12, 2016 09:22

Przemyslaw Klys

System Architect with over 14 years of experience in the IT field. Skilled, among others, in Active Directory, Microsoft Exchange and Office 365. Profoundly interested in PowerShell. Software geek.

Share
Published by
Przemyslaw Klys

Recent Posts

Active Directory Replication Summary to your Email or Microsoft Teams

Active Directory replication is a critical process that ensures the consistent and up-to-date state of…

3 weeks ago

Syncing Global Address List (GAL) to personal contacts and between Office 365 tenants with PowerShell

Hey there! Today, I wanted to introduce you to one of the small but excellent…

5 months ago

Active Directory Health Check using Microsoft Entra Connect Health Service

Active Directory (AD) is crucial in managing identities and resources within an organization. Ensuring its…

7 months ago

Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module

In today's digital age, the ability to create compelling and informative HTML reports and documents…

8 months ago

How to Efficiently Remove Comments from Your PowerShell Script

As part of my daily development, I create lots of code that I subsequently comment…

9 months ago

Unlocking PowerShell Magic: Different Approach to Creating ‘Empty’ PSCustomObjects

Today I saw an article from Christian Ritter, "PowerShell: Creating an "empty" PSCustomObject" on X…

9 months ago