Categories: ExchangePowerShell

Exchange 2013 – GrantSendOnBehalfTo nadpisuje wcześniejsze uprawnienia SendOnBehalf dla skrzynki pocztowej

Zmiana ustawienia Send On Behalf Exchange 2010 / Exchange 2013 lub Exchange 2016 jest czynnością, którą można wykonać w prosty sposób z ECP lub ECM. Niestety przy próbie zmian uprawnień Send On Behalf z poziomu PowerShell czynność ta staje się trochę bardziej ryzykowna.

Opis Problemu

Większość osób przy pierwszej możliwej sposobności użyje komendy

Set-Mailbox <UserToAddPermissionsTo> -GrantSendOnBehalf <UserToGivePermissionsTo>

W założeniu prosta komenda powershellowa ma niestety jedną wadę. Nadpisuje pole które ustawia, w tym przypadku nadpisując ustawienia GrantSendOnBehalf. O ile w pierwszej chwili nie jest to problem, bo zazwyczaj pole to jest puste. O tyle przy większych środowiskach Exchange, gdzie takie uprawnienia są już nadane wcześniej może to powodować duże problemy przy próbie zmiany pola GrantSendOnBehalf, a nadpisanie go najcześciej skutkuje usnięciem dużej grupy osób.

Rozwiązanie

Na szczęście jest prosta metoda by nie nadpisywać tych ustawień. Poniżej możecie znaleźć kilka komend, które potrafią ułatwić życie administratora Exchange.

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}
}

Podstawowe użycie komend Exchange PowerShell opisanych powyżej:

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 20 marca, 2016 12:24

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…

2 tygodnie 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 miesięcy 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 miesięcy 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 miesięcy 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 miesięcy 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 miesięcy ago