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

Posted on 2014-08-19
Last Modified: 2015-03-27
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?
Question by:RCOtech
    LVL 16

    Expert Comment

    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.
    LVL 3

    Accepted Solution

    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

    Author Comment

    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?
    LVL 3

    Expert Comment

    by:Liam Somerville
    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.
    LVL 56

    Expert Comment

    by:Cliff Galiher
    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?)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now