For Single User
$user = "account name"
$primarySMTP = "Name@primarysmtp.com"
$secondarySMTP = "nName@secsmtp.com"
$newUPN = "name@newupn.com" # Update this to the new UPN
# Update the UPN
Set-ADUser -Identity $user -UserPrincipalName $newUPN
# Set the primary email address
Set-ADUser -Identity $user -EmailAddress $primarySMTP
# Add the primary SMTP address to proxyAddresses
Set-ADUser -Identity $user -Add @{proxyAddresses="SMTP:$primarySMTP"}
# Add the secondary SMTP address to proxyAddresses
Set-ADUser -Identity $user -Add @{proxyAddresses="smtp:$secondarySMTP"}
For bulk Users.
CSV File Format
| Username | PrimarySMTP | SecondarySMTP | NewUPNSuffix |
| jdoe | jdoe@prismtp.com | jdoe@secsmtp.com | newdomain.com |
| asmith | asmith@prismtp.com | asmith@secsmtp.com | newdomain.com |
# Import the CSV file
$users = Import-Csv -Path "C:\path\to\users.csv"
foreach ($user in $users) {
$username = $user.Username
$primarySMTP = $user.PrimarySMTP
$secondarySMTP = $user.SecondarySMTP
$newUPNSuffix = $user.NewUPNSuffix
# Retrieve the current user's UPN
$currentUPN = (Get-ADUser -Identity $username -Properties UserPrincipalName).UserPrincipalName
# Extract the username from the current UPN
$usernamePart = $currentUPN.Split('@')[0]
# Construct the new UPN
$newUPN = "$usernamePart@$newUPNSuffix"
# Update the UPN
Set-ADUser -Identity $username -UserPrincipalName $newUPN
# Set the primary email address
Set-ADUser -Identity $username -EmailAddress $primarySMTP
# Add the primary SMTP address to proxyAddresses
Set-ADUser -Identity $username -Add @{proxyAddresses="SMTP:$primarySMTP"}
# Add the secondary SMTP address to proxyAddresses
Set-ADUser -Identity $username -Add @{proxyAddresses="smtp:$secondarySMTP"}
}