Script repository

Add Send As delegates to Send On Behalf list

Updated on: Jan 18, 2026, Views: 6087

Exchange

The script adds all Send As delegates of a mailbox to the Send On Behalf delegates list of the mailbox. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.

# 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))
    {
        continue
    }
    
    $objReference = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
    $objReference.ObjectSid = $trustee.ObjectSid
    $sendOnBehalfOf.Add("ADS_PROPERTY_APPEND", $objReference)
}

if ($sendOnBehalfOf.Count -eq 0)
{
    return
}

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

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.