Script repository
The script copies Send As, Send On Behalf Of and Mailbox Rights permissions from the specified mailbox to the mailbox of the current user. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.
In the script, the $sourceUserDNAttribute variable specifies the name of the property to get the object representing the source mailbox from.
$sourceUserDNAttribute = "assistant" # TODO: modify me
# Get source mailbox DN.
try
{
$sourceUserDN = $Context.TargetObject.Get($sourceUserDNAttribute)
}
catch
{
$Context.LogMessage("Source user not specified", "Warning")
return
}
$sourceUser = $Context.BindToObjectByDN($sourceUserDN)
if ($sourceUser.RecipientType -ne "ADM_EXCHANGERECIPIENTTYPE_MAILBOXENABLED")
{
$Context.LogMessage("The specified user does not have a mailbox", "Warning")
# Clear the attribute.
$Context.TargetObject.Put($sourceUserDNAttribute, $NULL)
$Context.TargetObject.SetInfo()
return
}
if ($sourceUser.RecipientLocation -ne $Context.TargetObject.RecipientLocation)
{
$Context.LogMessage("Target mailbox and source mailbox are hosted in different Exchange Organizations", "Warning")
# Clear the attribute.
$Context.TargetObject.Put($sourceUserDNAttribute, $NULL)
$Context.TargetObject.SetInfo()
return
}
# Get source mailbox Exchange properties.
$sourceMailboxParams = $sourceUser.GetMailParameters()
# Create an empty instance of the 'AdmExchangeMailboxParameters' class.
$mailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
# Copy 'Send As' permissions.
$mailboxParams.SendAs = $sourceMailboxParams.SendAs
# Copy 'Send on Behalf Of' permissions.
$mailboxParams.GrantSendOnBehalfTo = $sourceMailboxParams.GrantSendOnBehalfTo
# Copy 'Mailbox Rights'
$mailboxParams.MailboxRights = $sourceMailboxParams.MailboxRights
# Save the changes
$Context.TargetObject.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
# Clear attribute
$Context.TargetObject.Put($sourceUserDNAttribute, $NULL)
$Context.TargetObject.SetInfo()
Comments 0
You must be signed in to comment.