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.

Script Repository

Add Send As delegates to Send On Behalf list

October 15, 2021 Views: 1139

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
PowerShell
# 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 'Send On Behalf'
$newMailboxParams.GrantSendOnBehalfTo = $sendOnBehalfOf
$user.SetMailParameters($newMailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers