Active Directory Script – update users UPN from txt file

$oldSuffix = "olddomain.com"

$newSuffix = "newdomain.com"

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

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

$_ | Set-ADUser -UserPrincipalName $newUpn

}