Hello,
Thank you for specifying. Please, find the script below. The script grants Full Access and Send As permissions to the users specified in the AD object picker parameter over the mailbox of the object the custom command is executed on. In the script:
- $trsuteeDNsParamName - Specifies the name of the custom command parameter (with the param- prefix) used to select Active Directory objects to grant Full Access and Send As permissions to.
- $valueSeparator - Specifies the value separator used in the configuration of the AD object picker parameter whose name is specified in the $trsuteeDNsParamName variable.
$trsuteeDNsParamName = "param-Users" # TODO: modify me
$valueSeparator = ";" # TODO: modify me
# Grant permissions
$trsuteeDNs = $Context.GetParameterValue($trsuteeDNsParamName).Split($valueSeparator)
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
$mailboxRights = $mailboxParams.MailboxRights
$sendAs = $mailboxParams.SendAs
$sendAs.OverrideOldValues = $False
foreach ($dn in $trsuteeDNs)
{
# Add Send as permission
$sendAsObjReference = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$sendAsObjReference.ObjectDN = $dn
$sendAs.Add("ADS_PROPERTY_APPEND", $sendAsObjReference)
# Add Full Mailbox Access permission
$fullAccessObjReference = New-Object "Softerra.Adaxes.Adsi.AdmObjectReference"
$fullAccessObjReference.ObjectDN = $dn
$permission = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxPermission"
$permission.AllowedRights = "ADM_EXCHANGE_MAILBOX_RIGHTS_FULL_ACCESS"
$permission.Trustee = $fullAccessObjReference
$permissionModification = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxRightsModification"
$permissionModification.Operation = "ADS_PROPERTY_APPEND"
$permissionModification.Permission = $permission
$mailboxRights.AddModification($permissionModification)
}
# Save the changes
$mailboxParams.MailboxRights = $mailboxRights
$mailboxParams.SendAs = $sendAs
$user = $Context.BindToObjectEx($Context.TargetObject.AdsPath , $True)
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")