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

ago by (720 points)

1 Answer

ago by (305k points)
0 votes

Hello Josh,

The script should work just fine no matter of the mailbox type. At the same time, the below line will only work if the target mailbox resides in on-premises Exchange. In case of mailboxes from Exchange Online, you need to remove the line.

$Context.TargetObject.DeleteMailbox()
ago by (720 points)
0

Hello again,

I tested with removing the suggested line of code (remmed it out). I noted that while using the script I provided the email addresses from the user I deleted still did not transfer to another Exchange Online mailbox. I received the following error:

Delete User w/Email Migration' - Run PowerShell script 'Transfer E-mail Address to Another User' for the user
        [Error] Exception calling "SetMailParameters" with "2" argument(s): "Proxy address 'smtp:JMcTest2@domain.com' is already used by 'Jim McTest2 (domain.com\Thin Client Users)'." Stack trace: at <ScriptBlock>, <No file>: line 36

The user that was deleted didn't just have the above listed email addresses and none were transfered to the other account.

ago by (305k points)
0

Hello,

The error is expected and comes from Exchange Online, not Adaxes or the script. The thing is that you cannot set one email address to multiple users in Exchange Online. At the same time, there is no possibility to delete mailboxes like in on-premises Exchange. The common practice for such cases is to just give corresponding users full access to the mailbox. That is where you can use the Modify Exchange properties action: https://www.adaxes.com/help/AutomateExchangeMailboxConfiguration.

ago by (720 points)
0

Thank you for the clarification, I do believe we still would need a mechanism to first remove the mailbox then assign any email addresses from that removed mailbox to another specified user.

Would it be possible to split the process

First step would be to export a list of the current exchange online email addresses for the deleted user to say a txt or csv.

Second step would be a separate command where an admin can select the previously exported addresses and import them into another selected mailbox. This would be after verifying the previous users mailbox was removed.

We already have a separate script that outputs the previous users email addresses to a txt file prior to deletion, just curious if that (after some modification) can be used to provide the email addresses needed to be added to another mailbox.

ago by (305k points)
0

Hello,

The script you provided in the initial request saves email addresses of the target mailbox to the CustomAttributeTextMultiValue1 property of the account assistant. You can use that to add them to the mailbox when the corresponding account mailbox is deleted. However, it will require writing another script.

Related questions

Hello, We've currently been running the script below to process the migration of all emails from one account to another when a user is deleted. What we are hoping to do is ... than 30 days and need to track the time frame. Any guidance would be appreciated. JT

asked Jul 31, 2024 by jtop (720 points)
0 votes
1 answer

Hi All, I'm trying to use the powershell script provided here: https://www.adaxes.com/script-repository/move-mailbox-tofrom-microsoft-365-s579.htm Unfortuntately when executing ... credentials but I do not know why this error is happening. Thanks in advance

asked Aug 1, 2023 by curtisa (350 points)
0 votes
1 answer

Hi Team! I'm currently looking for a solution to create an exchange mailbox on-premise, sync it to Office 365 and assign the license in one business rule. I didn't ... solution from our side? Please let me know how to configure this. Best Regards Marco Jandl

asked Apr 6, 2022 by marco_jandl (60 points)
0 votes
1 answer

Hi all I need to modify the template $remoteRoutingAddressTemplate with the default exchange option automatically update email addresses disable. How i make it?

asked Nov 28, 2022 by Simone.Vailati (500 points)
0 votes
1 answer

Hi, is it possible to export automatically the exchange online mailbox of a user to a .PST file on our archive server before the user is deleted? Kind regards, Fabian

asked Oct 26, 2023 by fabian.p (380 points)
0 votes
1 answer