Change UPN on Office365 manually using Powershell

Clear2all Professional Blog new

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 "[email protected]" -NewUserPrincipalName "[email protected]"

or using below command

Get-MsolUser -UserPrincipalName [email protected] | Set-MsolUserPrincipalName -NewUserPrincipalName [email protected]

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.

Leave a Reply

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