Bulk update Primary SMTP address in Office 365

Question

Friday, October 4, 2019 2:28 PM

Hello,

we need to change massively the domain portion of the Primary SMTP Address to the new domain. E.g. from timothy@olddomain.com to timothy@newdomain.com, from max@olddomain.com to max@newdomain.com .....

We have Office 365 Business Premium and over 100 users. They already have the new SMTP address as an alias.

Users with other domains have not to be updated.

Thank you in advance.

Norma

All replies (7)

Saturday, October 5, 2019 8:38 AM ✅Answered | 3 votes

Hi Norma,

First, please confirm that the new domain has been added to Office 365 successfully:
/en-us/office365/admin/setup/add-domain?view=o365-worldwide

Then connect to Exchange Online PowerShell with an Office 365 Global Admin or Exchange Admin:
/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/connect-to-exchange-online-powershell?view=exchange-ps

Then you can use this simple script below to update PrimarySMTPAddresses of all users of that specific old domain. Don't forget to set $oldDomain and $newDomain variables in the first two lines correctly by changing "olddomain.com" and "@newdomain.com" values to the domains in your environment.

$oldDomain = "@olddomain.com"
$newDomain = "@newdomain.com"
$mailboxes = (Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox).where{$_.PrimarySmtpAddress -like "*$oldDomain"}
foreach ($mbx in $mailboxes){
$newSMTPAddress = $mbx.PrimarySmtpAddress -split '@'
$newSMTPAddress = $newSMTPAddress[0] + $newDomain
Write-Host "Processing: $mbx.Name -> $newSMTPAddress"
Set-Mailbox $mbx.Identity -WindowsEmailAddress $newSMTPAddress
} 

Regards,
Burak V.


Thursday, October 10, 2019 1:07 AM ✅Answered | 1 vote

Set-Mailbox onlineusera -EmailAddresses @{Remove=$temp}
Set-Mailbox onlineusera -EmailAddresses @{ADD=$temp2}

Replace with:

Set-Mailbox $Mailbox.Name -EmailAddresses @{Remove=$temp}
Set-Mailbox $Mailbox.Name -EmailAddresses @{ADD=$temp2}

Regards,

Kyle Xu

Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


Saturday, October 5, 2019 3:54 AM

You can use CSV upload with power shell.

refer below,

https://www.fmtconsultants.com/office-365-bulk-updates-via-powershell/

https://stackoverflow.com/questions/58192183/powershell-update-o365-ad-bulk-attributes-through-csv-file

/en-us/microsoft-365/compliance/bulk-import-external-contacts

https://o365info.com/bulk-import-contacts-to-exchange-online-office-365-using-powershell-part-1-of-2/

If you have Hybrid, You can use this tool easily,

http://www.wisesoft.co.uk/software/bulkadusers/default.aspx


Monday, October 7, 2019 3:00 AM

Hi,

Thanks for visiting our forum, here we mainly focus on general issues about Outlook desktop client but your question is more related to Exchange online. So I'll move your thread to the dedicated forum for Exchange online.

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thanks for your understanding and hope your question will be resolved soon.

Regards,

Aidan Wang

Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


Monday, October 7, 2019 1:28 PM

Hi Burak,

I tested the script on a small group of users and it works like a charm, but some accounts have both SMTP and SIP address. How can I update SIP also?

Thank you very much.

Norma

 


Tuesday, October 8, 2019 9:18 AM

You can use this script to modify SIP address from Exchange side:

$Mailboxes = Get-Mailbox -ResultSize unlimited  | where {$_.RecipientTypeDetails -eq "UserMailbox"}
$OldDomain = "aaa.onmicrosoft.com"
$newdomain = "bbbb.onmicrosoft.com"

foreach($Mailbox in $Mailboxes){
    $Datas = (Get-Mailbox $Mailbox.Name).emailaddresses
    foreach($Data in $Datas){
        if($Data -like "*SIP*"){
            if($Data -like "*$OldDomain*"){
                $temp= $Data
                $temp2 = $temp -replace $olddomain,$newdomain                
                Set-Mailbox onlineusera -EmailAddresses @{Remove=$temp}
                Set-Mailbox onlineusera -EmailAddresses @{ADD=$temp2}
            }
        }
    }
}

Regards,

Kyle Xu

Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


Wednesday, October 9, 2019 2:23 PM

You can use this script to modify SIP address from Exchange side:

$Mailboxes = Get-Mailbox -ResultSize unlimited  | where {$_.RecipientTypeDetails -eq "UserMailbox"}
$OldDomain = "aaa.onmicrosoft.com"
$newdomain = "bbbb.onmicrosoft.com"

foreach($Mailbox in $Mailboxes){
    $Datas = (Get-Mailbox $Mailbox.Name).emailaddresses
    foreach($Data in $Datas){
        if($Data -like "*SIP*"){
            if($Data -like "*$OldDomain*"){
                $temp= $Data
                $temp2 = $temp -replace $olddomain,$newdomain                
                Set-Mailbox onlineusera -EmailAddresses @{Remove=$temp}
                Set-Mailbox onlineusera -EmailAddresses @{ADD=$temp2}
            }
        }
    }
}

Regards,

Kyle Xu

Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

Impossibile eseguire l'operazione. Oggetto 'onlineuser' nel controller di dominio 'VI1PR02A006DC03.EURPR02A006.PROD.OUTLOOK.COM' non trovato.
    + CategoryInfo          : NotSpecified: (:) [Set-Mailbox], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : [Server=DB6PR02MB3000,RequestId=39307d25-0af3-4824-ae51-9590abe966b7,TimeStamp=09/10/2019 14:20:13] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] A76FC90E,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
    + PSComputerName        : outlook.office365.com