Say you end up with a wrong UserPrincipalName for an MSOL account which is sync’ed from On-Prem Active Directory like this: username@company.onmicrosoft.com, Which is obviously wrong UPN. The correct UPN supposed to be like username@company.com and it should match the user’s PrimarySMTPAddress.
I am sure you tried to correct it in Office 365 Admin Center, where UPN is grayed out. You may have tried MSOL PowerShell command Set-MSOLUser which does not have the parameter -UserPrincipalName. Right? That why you are here.
Solution: Easy Peacy. You have to use the another MSOL PowerShell command like this:
Set-MsolUserPrincipalName -UserPrincipalName username4892@company.onmicrosoft.com -NewUserPrincipalName username@company.com
That’s it. You have done it. Have an coffee! You deserve it! 🙂