Microsoft 365

Active Directory | Azure AD | Microsoft 365 Hybrid: Change UPN Suffix for all On-Premise Users (Bulk)

In a hybrid environment, it makes sense to configure an alternate UPN suffix so that users are not created in Azure AD with the username * In this post, I provide a script that allows you to create the UPN suffix and then change qll users of an OU to this suffix. Let’s dive in.

What I am talking about are this settings.

Configure Alternative UPN Suffix

If no new Suffix has been created yet, copy the following lines into ISE or Visual Studio Code.

Provide the new UPN Suffix in line 3.

# Variables

$newSuffix = ""

# Add Domain Suffix

Get-ADForest | Set-ADForest -UPNSuffixes @{Add="$newSuffix"}

Change UPN Suffix for all Users in a OU

Now let’s go for it.

Copy the code and edit line 3,4 and 8 to specify the OU of your users.

# Change UPN bulk

$oldSuffix = "pagr.inet"
$newSuffix = ""

Import-Module ActiveDirectory

$ou = "OU=Technicians,DC=pagr,DC=inet"

Get-ADUser -SearchBase $ou -filter * | ForEach-Object {
$newUpn = $_.UserPrincipalName -replace $oldSuffix,$newSuffix
$_ | Set-ADUser -UserPrincipalName $newUpn -Verbose

Done 😉

1 reply »

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.