Script repository
The script disables the mail forwarding feature for the target Exchange mailbox if the forwarding address matches a regular expression. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.
In the script, the $regex variable specifies the regular expression to use.
$regex = "\w+@abc\.com" # TODO: modify me
# Get forwarding recipient.
try
{
$altRecipientDN = $Context.TargetObject.Get("altRecipient")
}
catch
{
return
}
# Check the recipient's email address against the regular expression.
$object = $Context.BindToObjectByDN($altRecipientDN)
$mail = $object.Get("mail")
if ($mail -notmatch $regex)
{
return
}
# Disable mail forwarding.
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
$deliveryOptions = $mailboxParams.MailFlowSettings.DeliveryOptions
$deliveryOptions.IsModificationEnabled = $True
$deliveryOptions.ForwardingAddressModificationEnabled = $True
# Save changes
$Context.TargetObject.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
Comments 0
You must be signed in to comment.