Change UserPrincipalName for a user on Office 365 when synchronising with AD Connect

If you are having problems with some of your accounts in Office 365 where you have had to modify the name of an on-premise user but it’s not updating the login name of the user once an AD-Sync has completed, you can run this script below to give the user new UPN in Office 365

1
2
3
4
5
6
7
8
$currentUPN = <Users Current UPN>
$newUPN = <Users New UPN>

Import-Module Online
Connect-MSolService
Get-MSolUser -UserPrincipalName $currentUPN
Set-MSolUser -UserPrincipalName $currentUPN -NewUserPrincipalName $newUPN
Get-MSolUser -UserPrincipalName $newUPN

No errors should be seen when running this script if all works okay.

Leave a Reply

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