Change User UPN Address Using PowerShell For Single Or Multiple Users

This article will show you how to change User UPN for a single user and for multiple users using Windows PowerShell.

In the below screenshot you can see my user before.

To change the UPN, Open PowerShell from the domain controller (use run as administrator) and type the cmdlet below.

Set-User -UserPrincipalName test01@test.local -Identity test01

You can see the result below

You can also do a bulk change using a text file with usernames.

Import-Module ActiveDirectory

$oldSuffix = "test.local"

$newSuffix = "test.com"

Get-Content "C:\files\users.txt" | Get-ADUser | ForEach-Object {

$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)

$_ | Set-ADUser -UserPrincipalName $newUpn

}

Or do a bulk change to all the users In Active Directory

Import-Module ActiveDirectory

$oldSuffix = "test.local"

$newSuffix = "test.com"

$ou = "DC=test,DC=local"

Get-ADUser -SearchBase $ou -filter * | ForEach-Object {

$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)

$_ | Set-ADUser -UserPrincipalName $newUpn

}

Leave a Reply