Tuesday, October 29, 2013

Remove SendOnBehalfOf Permission From All Mailboxes

Today a client was looking for a method to remove a specific user from the SendOnBehalfOf permission of all mailboxes. The following script performs the task:
# Substitute the name of the user to remove for XXXX
$ToRemove=(Get-Mailbox XXXX).DistinguishedName

$mailboxes=get-mailbox -ResultSize unlimited
Foreach ($m in $mailboxes) {
    $current=$m.GrantSendOnBehalfTo
    $new=$current-$ToRemove
    Set-Mailbox $m -GrantSendOnBehalfTo $new
}
There are probably more efficient ways to do this, but this script gets the job done. The only reason it's awkward is because GrantSendOnBehalfTo is a list that needs to be modified. 

No comments:

Post a Comment