Powershell mass update UPN in AD

on
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Import-Module ActiveDirectory
$oldSuffix = "myolddomain.local"
$newSuffix = "mynewdomain.com"
$ou = "DC=yourdomain,DC=local"
$server = "Hostname"
Get-ADUser -SearchBase $ou -filter * | ForEach-Object {
$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)
$_ | Set-ADUser -server $server -UserPrincipalName $newUpn
}
Import-Module ActiveDirectory $oldSuffix = "myolddomain.local" $newSuffix = "mynewdomain.com" $ou = "DC=yourdomain,DC=local" $server = "Hostname" Get-ADUser -SearchBase $ou -filter * | ForEach-Object { $newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix) $_ | Set-ADUser -server $server -UserPrincipalName $newUpn }
Import-Module ActiveDirectory
$oldSuffix = "myolddomain.local"
$newSuffix = "mynewdomain.com"
$ou = "DC=yourdomain,DC=local"
$server = "Hostname"
Get-ADUser -SearchBase $ou -filter * | ForEach-Object {
$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)
$_ | Set-ADUser -server $server -UserPrincipalName $newUpn
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *