Posts Tagged ‘windows 2012’

You have more than 500-1000 users and need to change the UserPrincipalName?
Easy.

$ou="OU=marketing,DC=domain,DC=com"
$old='marketing.domain.com'
$new='accounting.domain.com'

Get-ADUser -Filter * -SearchBase $ou | ForEach-Object { $newUpn = $_.UserPrincipalName.Replace($old,$new) $_ | Set-ADUser -server $server -UserPrincipalName $newUpn }

ATTENTION!
Of course it is better to debug the command before running in production environment so place a “-WhatIf” mark after the command, like this:

Get-ADUser -Filter * -SearchBase $ou | ForEach-Object { $newUpn = $_.UserPrincipalName.Replace($old,$new) $_ | Set-ADUser -server $server -UserPrincipalName $newUpn -WhatIf }
Advertisements