Script/method to change UPN suffix for all users in Active Directory

Hi,

I hope someone can help. I have seen similar questions about this issue but am yet to find something that works for me. Although I know my way round AD pretty well, I am fairly novice when it comes to scripting. The new UPN suffix I want to apply is already in AD and I can easily manually change it for individual users but need a method to change it for all users. I want to (naturally) run this against a test OU first to ensure it works as expected. The distinguished name of the OU is "OU=users,OU=test,DC=Emea,DC=domain,DC=net".

As I say, as I am a novice when it comes to scripting, a complete description of how to do this would be ideal.

Thanks
ishamsiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
Use the following powershell script to accomplish this...

#Replace with the old suffix
$oldSuffix = 'old.suffix'

#Replace with the new suffix
$newSuffix = 'new.suffix'

#Replace with the OU you want to change suffixes for
$ou = "OU=users,OU=test,DC=Emea,DC=domain,DC=net"

#Replace with the name of your AD server
$server = "test"

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

Reference: http://community.spiceworks.com/scripts/show/1457-mass-change-upn-suffix


Thanks


Will
0
ishamsiAuthor Commented:
Hi Will. I already found that through google but can't get it working. Have you tested it? So I just save the script as <name>.ps1 and run it in powershell?
0
Will SzymkowskiSenior Solution ArchitectCommented:
You need to do a few things...

- Copy this into a txt file, change the file extension to .ps1
- Change the vaules for

#Replace with the old suffix
$oldSuffix = 'old.suffix' (your old domain suffix)

#Replace with the new suffix
$newSuffix = 'new.suffix' (your new domain suffix)

- I have replaced $OU = with your Testing OU location (no need to change)
- For $server = "add your DC server name"

Once you have changed those values you should then be able to run it on the Test OU and it should work fine. If you have any other questions let me know.
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

ishamsiAuthor Commented:
Yeah, I know about adding my own suffixes etc so that's what I did. Let me run it again now and I'll let you know the error I get.
0
Mike KlineCommented:
If your users are in the same OU there is also a GUI trick, select all users, right click and choose properties

Then you will see "properties for multiple items", go to the account tab, check UPN suffix, and use the drop down to select the new one.

Thanks

Mike
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ishamsiAuthor Commented:
Wow! Thanks for that Mike. Embarassingly, I can't believe I never noticed that. Perfect solution. Thanks a lot.
0
ishamsiAuthor Commented:
I should have noticed this! Top tip.
0
Mike KlineCommented:
People don't use that much anymore, it was a big deal when it was introduced in Windows 2003.

Glad to help

Thanks

Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.