Script Repository

Add Send As delegates to Send On Behalf list

October 15, 2021

The script adds all Send As delegates of a mailbox to the Send On Behalf delegates list of the mailbox. The delegates that are present in the Send on Behalf list will remain in place. The script can be executed in a business rule, custom command or scheduled task configured for the corresponding object type (e.g. User).

Edit Remove
# Get Exchange properties
$user = $Context.BindToObjectEx($Context.TargetObject.AdsPath , $True)
$mailboxParams = $user.GetMailParameters()

# Get 'Send As' delegates
$sendAs = $mailboxParams.SendAs
$newMailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
$sendOnBehalfOf = $newMailboxParams.GrantSendOnBehalfTo
$sendOnBehalfOf.OverrideOldValues = $False
for ($i = 0; $i -lt $mailboxParams.SendAs.Count; $i++)
    $trustee = $mailboxParams.SendAs.GetItem($i, [ref]"ADS_PROPERTY_NONE")
    if ([System.String]::IsNullOrEmpty($trustee.ObjectSid) -or [Softerra.Adaxes.Utils.WellKnownSecurityPrincipalInfo]::IsWellKnown($trustee.ObjectSid))
    $objReference = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
    $objReference.ObjectSid = $trustee.ObjectSid
    $sendOnBehalfOf.Add("ADS_PROPERTY_APPEND", $objReference)

if ($sendOnBehalfOf.Count -eq 0)

# Add delegates to 'Send On Behalf'
$newMailboxParams.GrantSendOnBehalfTo = $sendOnBehalfOf
$user.SetMailParameters($newMailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")

Comments ( 0 )
No results found.
Leave a comment