The script updates properties of a linked mailbox with the corresponding property values of the master account. The script should be executed by a custom command, business rule or scheduled task on the master account. If a property is empty in the master account, it will also be cleared for the linked mailbox.
In the script, the $propertiesToCopy variable specifies LDAP names of the properties to be updated.
PowerShell
$propertiesToCopy = @("givenName", "sn", "displayName") # TODO: modify me
# Get Exchange properties
$mailboxParams = $Context.TargetObject.GetMailParameters()
# Build linked mailbox ADS path
$linkedMailboxIdentity = $mailboxParams.LinkedMailbox
if ($linkedMailboxIdentity.ObjectDN)
{
$linkedMailboxPath = "Adaxes://" + $linkedMailboxIdentity.ObjectDN
}
elseif ($linkedMailboxIdentity.ObjectGuid)
{
$linkedMailboxPath = "Adaxes://<GUID=" + $linkedMailboxIdentity.ObjectGuid + ">"
}
elseif ($linkedMailboxIdentity.ObjectSid)
{
$linkedMailboxPath = "Adaxes://<SID=" + $linkedMailboxIdentity.ObjectSid + ">"
}
else
{
$Context.LogMessage("Unable to get object path: " + $linkedMailboxIdentity.Identifier, "Error")
return
}
# Update linked mailbox properties
$linkedMailbox = $Context.BindToObject($linkedMailboxPath)
foreach ($propertyName in $propertiesToCopy)
{
try
{
$value = $Context.TargetObject.Get($propertyName)
}
catch
{
$value = $NULL
}
$linkedMailbox.Put($propertyName, $value)
}
# Save changes
$linkedMailbox.SetInfo()
if("%department%" -ne ""){
$linkedMailbox.Put("Department", "%department%")}
This then prevents the script from failing or throwing errors because a property was blank.
Thank you for pointing out the behavior. We updated the script to clear linked mailbox properties if the corresponding properties of the master account are empty. If you need the linked mailbox properties to remain as is in such cases, you can keep using the script with your code.
Also, we added a variable that is used to specify the properties to update.