Update e-mail address via csv

%3CLINGO-SUB%20id%3D%22lingo-sub-1498207%22%20slang%3D%22en-US%22%3EUpdate%20e-mail%20address%20via%20csv%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1498207%22%20slang%3D%22en-US%22%3E%3CP%3Ehi%20guys%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20tenacy%20I%20manage%20has%20a%20lot%20of%20users.%20They%20have%20just%20bought%20a%20new%20domain%20name%20and%20want%20to%20assign%20a%20new%20primary%20address%20to%20everyone%20whilst%20keeping%20their%20exisiting%20address%20as%20an%20alias%20so%20not%20to%20miss%20future%20mails.%3C%2FP%3E%3CP%3EI%20know%20this%20can%20be%20done%20in%20the%20GUI%20now%20by%20batch%20selecting%20users%20and%20clicking%20change%20domain%20but%20this%20will%20base%20the%20new%20address%20on%20their%20current%20username%20and%20they%20might%20want%20to%20change%20the%20format%20of%20the%20new%20one.%3C%2FP%3E%3CP%3EI've%20looked%20at%20how%20to%20do%20this%20in%20powershell%20using%20a%20script%20to%20pull%20data%20from%20a%20csv%20where%20one%20column%20has%20existing%20address%20and%20another%20column%20with%20the%20new%20one.%20I've%20ran%20a%20test%20and%20it%20seems%20to%20of%20worked%20as%20expected%20but%20just%20wanted%20to%20check%20with%20you%20guys%20if%20these%20seem%20like%20the%20right%20commands%20so%20that%20there%20isn't%20a%20knock%20on%20effect%20i'm%20not%20aware%20of%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EImport-Csv%20'C%3Atemp%5Cfilelocation.csv'%20%7C%20ForEach-Object%20%7B%3CBR%20%2F%3ESet-Mailbox%20%24_.%22UserPrincipalName%22%20-WindowsEmailAddress%20%24_.%22NewEmailAddress%22%20-MicrosoftOnlineServicesID%20%24_.%22NewEmailAddress%22%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20only%20thing%20I%20noticed%20is%20a%20warning%20that%20appeared%20but%20apparently%20it%20can%20be%20ignored%3F%3C%2FP%3E%3CP%3EWARNING%3A%20UserPrincipalName%20%22emailaddress%22%20should%20be%20same%20as%20WindowsLiveID%20%22emailaddress%22%2C%20UserPrincipalName%20should%20remain%20as%22emailaddress%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1498207%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExchange%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1498240%22%20slang%3D%22en-US%22%3ERe%3A%20Update%20e-mail%20address%20via%20csv%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1498240%22%20slang%3D%22en-US%22%3EJust%20to%20add...%20this%20is%20the%20script%20we%20used%20to%20use%20(we%20haven't%20had%20to%20do%20this%20for%20a%20while)%20it%20used%20to%20work%20fine%20but%20now%20although%20it%20changes%20the%20username%20the%20primary%20e-mail%20was%20still%20the%20old%20one.%3CBR%20%2F%3E%3CBR%20%2F%3E%24users%20%3D%20Import-Csv%20c%3A%5Cpath%3CBR%20%2F%3Eforeach(%24user%20in%20%24users)%7B%3CBR%20%2F%3ESet-MsolUserPrincipalName%20-UserPrincipalName%20%24user.UserPrincipalName%20-NewUserPrincipalName%20%24user.FullEmail%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1498974%22%20slang%3D%22en-US%22%3ERe%3A%20Update%20e-mail%20address%20via%20csv%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1498974%22%20slang%3D%22en-US%22%3E%3CP%3EChanging%20the%20UPN%20value%20via%20PowerShell%20does%20not%20automatically%20result%20in%20changing%20the%20Primary%20SMTP%20address%2C%20unlike%20performing%20the%20same%20operation%20via%20the%20UI.%20Thus%20you%20need%20to%20change%20the%20SMTP%20address%20manually%2C%20and%20the%20code%20you%20have%20above%20should%20work%20just%20fine.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1502664%22%20slang%3D%22en-US%22%3ERe%3A%20Update%20e-mail%20address%20via%20csv%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1502664%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3Ethanks%20for%20confirming%20that%20the%20script%20i'm%20using%20should%20be%20ok%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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".

 

Thanks!

3 Replies
Highlighted
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
Highlighted

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.

Highlighted

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