Is there a way to set a user's UPN via GPO per OU?

We are trying to see if there is a way to set a user's UPN via GPO per OU. I haven't been able to find anything that will allow us to do this but wanted to see if anyone has before.

Let's say we have 3 OU's and each OU has different UPN's we want to assign, is there a way to do this via GPO so when we create a new user object in the specified OU, it appends the applicable UPN?
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.

ThinkPaperIT ConsultantCommented:
I think this can be possible via a script.. but not necessarily a GPO, as I see this more as a one-time change, not something you want to run every time a user logs on the domain. I see this more as a mass batch job that would change all existing accounts, and new accounts will be done as they come in.. is this kind of thing you are looking for?

Changes to the account like this would require the account that it is running on to have at least some kind of privileged access.. so I this more as a vbscript or Powershell that you want to execute on specific OUs.. now THAT can be possible, as the OU, username, UPN are all attributes for each account.
Liam SomervilleSenior Security ConsultantCommented:
You'd want something like this:
$Users = Get-ADUser -Filter * -SearchBase "OU=OUName,DC=YourDomain,DC=LOCAL"
foreach ($User in $Users)
    Get-ADUser $User | Set-ADUser -UserPrincipalName $($User.SamAccountName+"@YourDomain.LOCAL")
} # end foreach

Open in new window

You'd obviously want to modify the UPN section to your needs

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
RCOtechAuthor Commented:
Thank you for both of your responses. We will have to apply this to existing users.  We have lots of OU's per location, do you recommend running task scheduler to automate assignment of the UPN per OU for new user object creation?
Liam SomervilleSenior Security ConsultantCommented:
Existing locations can be modified using the above script. When creating users using the GUI, I believe you can set the UPN. If you create users using PowerShell, you can just add that to the end of the user creation process.
Cliff GaliherCommented:
Even if you have a lot of users, you wouldn't want to make this change via GPO. Group policies run during computer startup or logon. And a user's UPN is an object property, so there is no reason for it to be changed at every startup or logon. You'd instead use a one-off script that can target an OU. But you'd run the script manually, not as part if a GPO (what's the point of waiting for a GPO process?)
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
Microsoft Applications

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.