Change User UPN Address Using PowerShell For Single Or Multiple Users

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

Before Change

In the below screenshot you can see my user before.

Set-User

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

Multiple Users

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
}

Processing…
Success! You're on the list.

One Reply to “Change User UPN Address Using PowerShell For Single Or Multiple Users”

Comments are closed.