Change Users Office 365 Email (SMTP Address)

While reviewing users in Office 365 I noticed that some of the users had incorrect email addresses. Rather than using our companies email domain name they were using the Microsoft email domain (domain.onmicrosoft.com), In order to change the email domain (primary SMTP) address for these users I had to Connect to Exchange Online and run a few commands through PowerShell.

Due to the environment setup I could not change the primary SMTP address through the web portal. This is the error I received when trying (which is expected based on our setup):

The operation on mailbox “Jon Smith” failed because it’s out of the current user’s write scope. The action ‘Set-Mailbox’, ‘EmailAddresses’, can’t be performed on the object ‘Jon Smith’ because the object is being synchronized from your on-premises organization. This action should be performed on the object in your on-premises organization.

To connect to Office 365 (Exchange Online) following the instructions (or click here for the official Microsoft article – Connect to Exchange Online):

Step 1) Open PowerShell (as administrator) and run the following command:

$UserCredential = Get-Credential

Step 2) Sets the PowerShell environment for your Office 365 tenant:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Step 3) Sets your PowerShell session to use Microsoft Exchange Online:

Import-PSSession $Session

Step 4) Change your users email address (Primary SMTP) from [email protected] to [email protected]:

Set-Mailbox username -WindowsEmailAddress [email protected]

Step 5) Check the mailbox by running the following command:

Get-Mailbox -Identity [email protected]

Step 6) Disconnect your PowerShell session from Exchange Online:

Remove-PSSession $Session

If you have any questions or see an error please let me know. If you are looking for more  around PowerShell and Office 365 check here: http://powershell.office.com/

Leave a Reply

Your email address will not be published. Required fields are marked *

*