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

Supercharging Your Network Diagnostics with Globalping for NET

Ever wondered how to run network diagnostics like Ping, Traceroute, or DNS queries from probes…

1 tydzień ago

Automating Network Diagnostics with Globalping PowerShell Module

Are you tired of manually running network diagnostics like Ping, Traceroute, or DNS queries? The…

1 tydzień ago

Enhanced Dashboards with PSWriteHTML – Introducing InfoCards and Density Options

Discover new features in the PSWriteHTML PowerShell module – including New-HTMLInfoCard, improved layout controls with…

2 tygodnie ago

Mastering Active Directory Hygiene: Automating SIDHistory Cleanup with CleanupMonster

Security Identifier (SID) History is a useful mechanism in Active Directory (AD) migrations. It allows…

2 tygodnie ago

Upgrade Azure Active Directory Connect fails with unexpected error

Today, I made the decision to upgrade my test environment and update the version of…

2 tygodnie ago

Mastering Active Directory Hygiene: Automating Stale Computer Cleanup with CleanupMonster

Have you ever looked at your Active Directory and wondered, "Why do I still have…

2 tygodnie ago