How to Change Office 365 Users Primary Email Address in Bulk?

Featured image

There are various scenarios in which Admin needs to change the Office 365 users primary email address in bulk or add secondary email address in bulk. Some of the cases are:

With the help of PowerShell this task is made easier. You need to create a CSV with the list of username and the Primary email to be updated or the secondary email to be added.

Most of the scripts available in the net, doesn’t update the user principal name and Microsoft Online Services ID properly. When these details are not updated the user will not be able to login with his new username after the Primary email update. The below script will update those values in user properties and hence they will be able to login immediately with the new username.

PowerShell script to change users Primary email address

Step 1: Create a new CSV file with User, AliasEmailaddress as headers. Step 2: Now use the below cmdlet to import the CSV to PowerShell and change the users Primary email.

$csv = Import-Csv C:\Users\john\Desktop\email.csv
foreach ($line in $csv)
{
$SMTP ="SMTP:"+$line.AliasEmailaddress
Set-Mailbox -Identity $line.User -EmailAddresses $SMTP -WindowsEmailAddress $line.AliasEmailaddress -MicrosoftOnlineServicesID $line.AliasEmailaddress 
} 

Note: when you change the primary email address of the user to another domain, the new domain which you like to add should be included to the list of Trusted Domains.

PowerShell script to add Secondary email address to users in bulk

Step 1: Create a new CSV file with User, AliasEmailaddress as headers. Step 2:Now execute the below script in Windows PowerShell to import the CSV.

$csv = Import-Csv C:\Users\jack\Desktop\email.csv
foreach ($line in $csv)
{
$Mailbox= Get-Mailbox -Identity $line.User
$Primarymail=$Mailbox.PrimarySmtpAddress
$SMTP ="SMTP:"+$line.AliasEmailaddress
Set-Mailbox -Identity $line.User -EmailAddresses $SMTP,$Primarymail -WindowsEmailAddress $line.AliasEmailaddress -MicrosoftOnlineServicesID $line.AliasEmailaddress 
}

If you want to have a simple power packed GUI tool, you can use GingerEx for Office 365, which is available for $99.