365tips.be

Blogs about: Microsoft Teams, backgrounds, Intune, OneDrive, Exchange, Azure AD, Windows 10, Security, Tenant, Exchange, best-practice, tips and & tricks

👨💻 How to modify a 'Userprincipalname' from PowerShell in Microsoft 365 or Azure AD?

Customizing UPNs or UserPrincipalNames can be useful to perform manipulations at scale when, for example, companies merge or get a new domain name.

These adjustments are not possible today in a practical way in the Office 365 Portal.

Install the MSOnline module

Install-Module -Name MSOnline
1

Connect to Azure AD with these 2 commands

Connect-msolservice

Enter your username & password

1

Changing a UserPrincipalname (UPN) via PowerShell

Set-MsolUserPrincipalName -UserPrincipalName DebraB@JasperBernaers.com -NewUserPrincipalName DebraBerger@365tips.be

You can customize multiple UPNs with multiple lines:

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

Example after these adjustments of the userprincipalname

In this screenshot you can see the after UserPrincipalname change via PowerShell.

1

See also these PowerShell tips

Starting Powershell for managing Microsoft 365
How to install Azure AD preview module with PowerShell?
Tutorial: How to create and manage Microsoft Teams using PowerShell?
How to install and use PowerShell 7 ? - Administrator tools

About the author

Tagged: , ,
0 0 vote
Article review
Subscribe
Please let us know if there are
guest

5 Comments
Oldest
Latest Most Voted
Inline feedbacks
See all comments
Edgardo
Edgardo
11 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
stration.Automation.SetUserPrincipalName

brioche
brioche
9 months ago

Bonjour,
Comment mettre à jour d'autres attributs en masse ? Exemple : le numéro de téléphone ou la ville.

Windows10
Windows10
1 month ago

And for all Users in AzureAD ?

wpdiscuz   wpDiscuz
5
0
Would love to know your thoughts, please leave a comment.x
%d bloggers like this: