We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script repository

Update linked mailbox properties with values of the master account

September 05, 2023 Views: 1695

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.

Edit Remove
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()

Comments 2
avatar
Malcolm Mar 02, 2021
In order to avoid errors when it hits an empty property, I have updated my script with a check for each property not being blank as follows:

if("%department%" -ne ""){
$linkedMailbox.Put("Department", "%department%")}

This then prevents the script from failing or throwing errors because a property was blank.
avatar
Support Mar 02, 2021
Hello Malcolm,

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.
Leave a comment
Loading...

Got questions?

Support Questions & Answers