Change and update 'Userprincipalname' via PowerShell in Microsoft 365

Change and update 'Userprincipalname' via PowerShell in Microsoft 365

Modifying UPNs or UserPrincipalNames can be useful to perform manipulations at scale when, for example, companies merge or get a new domain name. These modifications are not possible in a practical way in the Office 365 Portal.

Install the MSOnline module

Install-Module -Name MSOnline
1

Connect to Azure AD

Connect-msolservice

Enter your username & password

1

Changing a UPN via PowerShell

Set-MsolUserPrincipalName -UserPrincipalName info@edu365tips.onmicrosoft.com -NewUserPrincipalName info@edu.365tips.be
1

You can adjust multiple UPNs with multiple lines:

Set-MsolUserPrincipalName -UserPrincipalName = The current UPN
NewUserPrincipalName = The new UPN.

Example for the modification of the 'userprincipalname'

In this screenshot you can see the previous UserPrincipalname.

1

Example after these adjustments of the userprincipalname

In this screenshot you can see the after UserPrincipalname.

1

See also these PowerShell tips

Starting with Powershell for the administration of Microsoft 365
How to install Azure AD preview module with PowerShell?
Tutorial: How to create and manage Microsoft Teams with PowerShell?
How to install and use PowerShell 7? - Administrator Tools

Jasper

Jasper

Welcome to 365tips.be. On this website you can read articles and experiences about Office 365 with focus on Microsoft Teams. Feel free to ask me a question and I will answer it in a blog post. Help others by giving feedback at the bottom of the articles. This blog is made in Dutch. The multilingual website is offered with best-effort machine translation.
0 0 votes
Product review
Subscribe
Please let us know if there are
guest
3 Responses
Oldest
Latest Most Voted
Inline feedbacks
See all comments
Edgardo
Edgardo
4 months ago

Set-MsolUserPrincipalName : Access Denied. You do not have permissions to call this cmdlet.
At line:1 char:1
+ Set-MsolUserPrincipalName -UserPrincipalName mmollica@XXXX.com -N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Set-MsolUserPrincipalName], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Admini
Automation.SetUserPrincipalName

brioche
brioche
2 months ago

Bonjour,
How do I communicate other attributes in mass? Exemple: the telephone number or the city.

3
0
Would love to know your thoughts, please leave a comment.x
()
x
%d bloggers liked this: