Update e-mail address via csv

New Contributor

hi guys,


The tenacy I manage has a lot of users. They have just bought a new domain name and want to assign a new primary address to everyone whilst keeping their exisiting address as an alias so not to miss future mails.

I know this can be done in the GUI now by batch selecting users and clicking change domain but this will base the new address on their current username and they might want to change the format of the new one.

I've looked at how to do this in powershell using a script to pull data from a csv where one column has existing address and another column with the new one. I've ran a test and it seems to of worked as expected but just wanted to check with you guys if these seem like the right commands so that there isn't a knock on effect i'm not aware of:


Import-Csv 'C:temp\filelocation.csv' | ForEach-Object {
Set-Mailbox $_."UserPrincipalName" -WindowsEmailAddress $_."NewEmailAddress" -MicrosoftOnlineServicesID $_."NewEmailAddress"


The only thing I noticed is a warning that appeared but apparently it can be ignored?

WARNING: UserPrincipalName "emailaddress" should be same as WindowsLiveID "emailaddress", UserPrincipalName should remain as"emailaddress".



3 Replies
Just to add... this is the script we used to use (we haven't had to do this for a while) it used to work fine but now although it changes the username the primary e-mail was still the old one.

$users = Import-Csv c:\path
foreach($user in $users){
Set-MsolUserPrincipalName -UserPrincipalName $user.UserPrincipalName -NewUserPrincipalName $user.FullEmail

Changing the UPN value via PowerShell does not automatically result in changing the Primary SMTP address, unlike performing the same operation via the UI. Thus you need to change the SMTP address manually, and the code you have above should work just fine.

@Vasil Michevthanks for confirming that the script i'm using should be ok