Sunday, January 20, 2013

Change UPN through Powershell Script

Import-Module ActiveDirectory

#Change old suffix according to your environment
$oldSuffix = 'WIN2K8.COM'

#Change new suffix according to your environment
$newSuffix = 'ABC.COM'

#Change OU according to environment, you want to change suffixes for
$ou = "OU=Test,DC=WIN2K8,DC=COM"

#Change the name of your AD server according to your environment
$server = "dc08.win2k8.com"

Get-ADUser -SearchBase $ou -filter * | ForEach-Object {$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)
$_ | Set-ADUser -server $server -UserPrincipalName $newUpn}

Note: Please make sure suffixes should be case sensitive according to your environment.

No comments:

Post a Comment