Active Directory mass UPN suffix change with PowerShell

Posted: 11 September 2015 in Microsoft
Tags: , , , , ,

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s