Change User Primary Email Address in Office 365 with PowerShell.
1. Run the PowerShell as administrator;
2. To run the scripts needed to change a user’s primary email address we must first set the script execution policy.
3. The execution policy needs to be RemoteSigned. RemoteSigned allows only downloaded scripts signed by a trusted publisher to be run. If Get-ExecutionPolicy doesn’t return RemoteSigned, it must be changed by typing the following cmdlet and entering a “y” when prompted;
4. Now Get-ExecutionPolicy returns RemoteSigned;
5. Next we need to provide Office 365 with administrative credentials to be able to make changes. We’re going to assign our credentials to the variable $cred;
$cred = Get-Credential
6. And PowerShell prompts for an Office 365 account with administrative permissions;
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection
Set-Mailbox -identity <firstname.lastname@example.org> -WindowsEmailAddress <email@example.com>
10. The Office 365 online administrative interface should show the new email address as the primary;
11. Don’t forget close seession;