Script repository
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.