Change UPN on Office365 manually using Powershell

Change UPN on Office365 manually using Powershell

In some circumstances the UPN changes on on-premise do not get updated to Azure/Office365. If you are syncing from your on-premise AD then updating the UPN in Azure using powershell is going to get overwritten the next time that your sync process runs but in a situation where its changed to correct value then it will just be replaced by same value. This manual process can be used for speeding up the change or making the change if sync is unsuccessful.

If I have understood the question correctly then by updating the UPN of the user in question on your on-prem domain controllers should fix the issue. The next time the sync process occurs, the updated info will go up to Azure.

For changing UserprincipalName on Office365 using powershell first we need to connect to MSOLService using below command

connect-msolservice

above command will prompt for credentials which needs to be entered.

The Command to check full properties list of a user is below where Test Username is the name of the user.

Get-MSOLUser -SearchString "Test Username" | fl

Below is the set-msoluserprincipalname powershell command which is used to change the UserPrincipalName.

Set-MsolUserPrincipalName -UserPrincipalName "Firstname.lastname@Test.com" -NewUserPrincipalName "NewFirstname.lastname@Test.com"

or using below command

Get-MsolUser -UserPrincipalName user1@Test.com | Set-MsolUserPrincipalName -NewUserPrincipalName user2@Test.com

The Command to check full properties list of a user is below where Test Username is the name of the user.

Use below command to check the change is successful

Get-MSOLUser -SearchString "Test Username" | fl

One of the common issue experienced during this manual process is the “Access Denied” error message.

Set-MsolUserPrincipalName : Access Denied. You do not have permissions to call this cmdlet

If you are using Global Administrator account on Office365, you should have permission to update user properties. This error message is little misleading where most of the time its to say that we are searching for an non-existent UPN name in the ‘-UserPrincipalName’ parameter.

Vamshi B

Recent Posts

How to install Firefox browser using Powershell

How to install of FireFox browser using PowerShell Sometimes you would like to install Firefox…

2 years ago

How to install chrome with Powershell?

Quick way to install chrome on windows with Powershell? Launch the Powershell and run below…

2 years ago

How to Fix PowerShell Script Not Digitally Signed Error?

How to Fix PowerShell Script Not Digitally Signed Error? When a script with a .ps1…

2 years ago

Powershell Cheat Sheet for beginners

Powershell Cheat Sheet for beginners PowerShell has become something of an ace in the hole…

2 years ago

Can you use Linux commands in Powershell?

Today we discuss one of a few questions a lot of sysadmins and IT Admins…

2 years ago

Backing Up an SQL Database with PowerShell

Backing Up an SQL Database with PowerShell Before making any changes in the production environment,…

2 years ago

This website uses cookies.