Change the UPN of multiple users using PowerShell (Microsoft Entra ID)

Marcelo Gonçalves
4 min readOct 23, 2023

--

Alterar o UPN de vários usuários usando o PowerShell (Microsoft Entra ID)

Imagine um cenário onde você precisa trocar o domínio de um tenant com alguns usuários já cadastrados, realmente seria algo penoso acessar cada perfil e trocar o antigo UPN pelo novo.Uma das maneiras de resolver esse processo penoso seria exportar os usuários cadastrados e criar uma lista de comandos e executar no Powershell ISE. Veja os passos logo abaixo:

Imagine a scenario where you need to change the domain of a tenant with some users already registered, it would really be difficult to access each profile and exchange the old UPN for the new one. One of the ways to solve this painful process would be to export the registered users and create a list of commands and run in Powershell ISE. See the steps below

  1. Entre no portal do Azure (Faça o login):

Sign in to the Azure portal (Sign in):

2. No Search do Portal do Azure digite active directory e depois clique emMicrosoft Entra ID:

In the Search of the Azure Portal, type active directory and then click on Microsoft Entra ID:

3. Na coluna Manage clique em Users:

In the Manage column, click on Users:

4. Clique no box ao lado do Display Name para selecionar todos os
usuários e depois clique em Download Users

Click the box next to Display Name to select all
users and then click Download Users

5. Clique em Start:

Click Start:

6. Clique em File is ready! Click here to download:

Click File is ready! Click here to download:

7 — Abra o arquivo no Excel e faça a configuração para delimitar os campos e deixe apenas a coluna userPrincipalName:

Open the file in Excel and configure it to delimit the fields and leave only the userPrincipalName column:

8- Copie a coluna para o Notepad e faça a substituição do antigo domínio
para o novo:

Copy the column to Notepad and replace the old domain with the new one:

9 — Agora precisamos concatenar no Excel as duas informações com seguinte comando:

Now we need to concatenate the two pieces of information in Excel with the following command:

Set-AzureADUser -ObjectId EmilyB@M365B959982.OnMicrosoft.com -UserPrincipalName EmilyB@labsazure.cloud

10 — Abra o Powershell ISE e digite os comandos abaixo para logar:

Open Powershell ISE and type the commands below to log in:

Connect-AzureAD

11 — Execute os comandos concatenados:

Execute the concatenated commands:

12. Voilá! Foram atualizadas as UPNs dos usuários:

Voila! User UPNs have been updated:

Esse processo ajuda quando é preciso trocar o UPN dos usuários para um novo domínio. Cada tenant pode ter 900 custom domain.

This process helps when you need to change users’ UPN to a new domain. Each tenant can have 900 custom domains.

--

--

Marcelo Gonçalves
Marcelo Gonçalves

Written by Marcelo Gonçalves

Microsoft Solutions Architect | Teacher | Linux | MCP | MCT | LGPDF™ | OCI | AWS

No responses yet