PowerShell Script to Bulk Update UPN (UserPrincipalName) Suffix in a Single Non-Routable Domain.

As part of the Office 365 Configuration and migration project, we’ve had to define and create an alternate upn (UserPrincipalName) suffix for an internal Active Directory domain that is not publicly routable. Updating the upn for every user in the Active Directory Domain could be a tedious task if done manually. Following is a screen shot of a user object upn before the script run:


To quickly and efficiently accomplish this task while avoiding unnecessary errors, I wrote a short PowerShell function "update-upnsuffix" to make the updates by OU (Organizational Unit):


function Update-UpnSuffix{

Get-ADUser -Filter * -SearchBase "OU=Production_OU,OU=Users-All,DC=Genesysconsults,DC=net" |
ForEach-Object { Set-ADUser -Identity $_ -UserPrincipalName (($_.GivenName) + '.' + ($_.Surname) + '@' + ($newupn)) }

} Update-UpnSuffix

The first line of the script uses the Get-ADForest cmdlet to extract the first element of the upnsuffixes collection property and assigns it to the $newupn string variable.

The second line of the script queries the user objects in the specified OU , pipes the result to a ForEach-Object cmdlet and updates the upn for each user object in the result set. Screen shot of an in-scope user object after the script run is attached:


The script could be adapted to any Active Directory environment.

This entry was posted in Active Directory Domain Services, Office 365, PowerShell, PowerShell 3.0, Powershell 4.0, Script, Scripts, Windows Server 2008 R2 Backup, Windows Server 2012 R2 and tagged , , , , , , , , , . Bookmark the permalink.

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 )

Facebook photo

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

Connecting to %s