To start with I need to create the UPNS in AD and then exported a list of users
Get-Mailbox -ResultSize Unlimited |Select-Object UserPrincipalName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} | Export-CSV c:\temp\exportsmtpUserPrincipalName.csv -NoTypeInformation
Once I had my list of users in different txt documents I can run the below PowerShell script to change the UPN’s
Import-Module ActiveDirectory
$oldSuffix = “abc.local”
$newSuffix = “abc.com”
Get-Content “C:\files\users.txt” | Get-ADUser | ForEach-Object {
$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)
$_ | Set-ADUser -UserPrincipalName $newUpn
}
Huseyin Kartal
Latest posts by Huseyin Kartal (see all)
- Find User SID - 01 Haziran 2021
- Oracle client Deployment & Upgrade - 12 Mart 2021
- Active Directory Dcdiag Service Test & Advertsing Test failure - 15 Ocak 2021