Hello,
We've previously had assistance in implementing a method to transfer email addresses to a specified user via a powershell script for our on-prem Exchange. This has functioned perfectly, but we are now looking to move our Exchange into Exchange Online and after some testing, I was unable to get our existing script to function. Is this still possible in Exchange Online?
We are not looking to have emails transfered from Exchange Online to our on-prem mailboxes, but would just like to have it transfer the emails from one Exchange Online mailbox to another.
We use a custom parameter called "assistant" to give us the assigned user. Here is the code:
$userDN = "%assistant%" # TODO: modify me
# Get all E-mail addresses from the target user
try
{
$sourceMailboxParams = $Context.TargetObject.GetMailParameters()
}
catch
{
return # The user doesn't have an Exchange account
}
$sourceEmailAddresses = $sourceMailboxParams.EmailAddresses
# Add the user's e-mail addresses to e-mail addresses of the receiving user
$targetMailboxParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailboxParameters"
$targetEmailAddresses = $targetMailboxParams.EmailAddresses
$targetEmailAddresses.OverrideOldValues = $False
$emailAddressesInfo = @()
$date = (Get-Date).AddDays(30).ToString("d")
foreach ($sourceEmailAddress in $sourceEmailAddresses.GetAddressesByPrefix("smtp"))
{
$emailAddress = $targetEmailAddresses.CreateAddress("ADM_EXCHANGE_ADDRTYPE_SMTP", $null)
$emailAddress.Address = $sourceEmailAddress.Address
$emailAddress.IsPrimary = $False
$targetEmailAddresses.Add("ADS_PROPERTY_APPEND", $emailAddress)
$emailAddressesInfo += $emailAddress.Address + ":$date"
}
$targetMailboxParams.EmailAddresses = $targetEmailAddresses
# Delete the source mailbox
$Context.TargetObject.DeleteMailbox()
# Save the changes for target mailbox
$user = $Context.BindToObjectByDN($userDN)
$user.SetMailParameters($targetMailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
# Update the CustomAttributeTextMultiValue1 property of the receiving user with the new addresses
$date = (Get-Date).AddDays(30).ToString("d")
$user.PutEx("ADS_PROPERTY_APPEND", "adm-CustomAttributeTextMultiValue1", $emailAddressesInfo)
$user.SetInfo()
Please let me know if you require more clarification.
Regards,
Josh