In Active Directory, the User Principal Name (UPN) is the user's sign-in name in the format user.name@domain.com, and it is stored in the userPrincipalName attribute of the user object. The part before the @ sign is called the UPN prefix, and the part after it is called the UPN suffix. This value is unique across the forest and is resolved through the global catalog. When a forest is created, the only available UPN suffix is the DNS name of the domain itself. If the domain name is a name that cannot be routed on the internet, such as firatboyan.local, the UPN value of the users does not match their corporate email addresses.
This mismatch usually goes unnoticed on the on-premises side. The problem appears when the users start to be synchronised with Microsoft Entra ID. In the default configuration, Microsoft Entra Connect takes the cloud sign-in name from the on-premises userPrincipalName value. If the suffix of this value does not match a verified custom domain in the tenant, Entra ID calculates the UPN value of the user as MailNickName@{Tenant}.onmicrosoft.com. For the Microsoft 365 sign-in name of a user to be the same as the email address, the whole on-premises UPN must match this address and the suffix must be verified in the tenant. If Alternate login ID was selected for the sign-in name during installation, the source is the selected attribute and not userPrincipalName, and a change made here does not affect the cloud sign-in name.
In this article, I add the firatboyan.com UPN suffix to the firatboyan.local forest and move the UPN values of my users to this suffix. For a few Active Directory user objects, this change can be made individually in Active Directory Users and Computers. When tens or even hundreds of users are involved, a manual change takes time and is also prone to error. For this reason, I perform the operation with PowerShell, first for all Active Directory users and then only for the users in a specific organizational unit (OU). In the last section, I explain the effects of the change on sign-in and on the hybrid side, and the rollback method.
The Active Directory steps in this article do not depend on a specific Windows Server version. The cmdlets used here work in the same way from the ActiveDirectory module that was introduced with Windows Server 2008 R2 onwards. The screenshots were taken on Windows Server 2022.
1- Pre-Check List
Before I move on to the commands, I verify the items below. The first 3 items apply to every environment. The 2 items about Entra ID are required only in hybrid environments where the users are synchronised with Microsoft Entra Connect.
|
Check |
Expected State |
|
Permission to add a UPN suffix |
The account has write permission on the uPNSuffixes attribute of the Partitions container object in the configuration partition. Members of Enterprise Admins have this permission. |
|
Permission to change the user UPN |
The account has effective write permission on the userPrincipalName attribute of the target user objects. Account Operators membership is not sufficient for protected administrator accounts. Because protected accounts do not inherit the permissions granted on the OU, the permission is verified separately if these accounts are in scope. |
|
PowerShell module |
The Active Directory commands are run on a domain controller where the ActiveDirectory module is installed, or on a management computer with RSAT installed. |
|
Custom domain in Entra ID (hybrid) |
The domain with the same name as the suffix to be added has been added to the tenant as a custom domain and is in the Verified state. |
|
Synchronisation of UPN updates (hybrid) |
The SynchronizeUpnForManagedUsers feature is enabled in the tenant. This feature allows the UPN change of licensed managed users to be applied to Entra ID. |
In a hybrid environment, if the UPN suffix is changed before the custom domain is verified, the UPN value of the users in Entra ID does not take the new suffix and continues to be calculated with the onmicrosoft.com suffix.
2- Adding the UPN Suffix to the Forest
The UPN suffixes that can be assigned to a user are defined at forest level. For this reason, the new suffix is added once and becomes available in all domains in the forest. The added suffix does not need to have a real DNS zone on the Active Directory side.
Step 1 - Listing the Existing UPN Suffixes
First, I list the alternative UPN suffixes defined in the forest with the command below. The UPNSuffixes field shows only the suffixes that were added later. firatboyan.local, which is the DNS name of the domain itself, is the default suffix and is not kept in this list. Therefore, an empty field means that no additional UPN suffix has been defined in the forest yet.
Get-ADForest | Format-List UPNSuffixes

I also perform the same check in the Active Directory Domains and Trusts console. The UPN Suffixes tab in the Properties window of the Active Directory Domains and Trusts node at the top of the console does not contain an additional UPN suffix either.


Step 2 - Adding the New UPN Suffix
I add the firatboyan.com UPN suffix to the forest with the command below. The @{Add="..."} expression adds to the existing list and does not change any other suffixes in the list.
Get-ADForest | Set-ADForest -UPNSuffixes @{Add="firatboyan.com"}
After the suffix is added, I retrieve the list again to verify the result.
Get-ADForest | Format-List UPNSuffixes

Checkpoint
The firatboyan.com value is listed in the UPNSuffixes field.
The same addition can also be made on the UPN Suffixes tab of the Active Directory Domains and Trusts console. I can also see the suffix that I added with PowerShell on this tab.

3- Changing the UPN Suffix of All Users
Adding the suffix to the forest does not change the UPN value of the users automatically. The new suffix only becomes selectable. In this section, I change the UPN suffix of all users in the domain to firatboyan.com without separating them by organizational unit (OU).
Step 3 - Listing the Current UPN Values
I retrieve the current UPN values of my users with the command below. To keep the command output short, I limit the result to 25 users with the -ResultSetSize 25 parameter. This parameter does not return the first 25 users in alphabetical order. It returns the first 25 records that the domain controller returns. Sort-Object then sorts these records by name. I use the same parameter in the listing commands in the later steps of the article.
Get-ADUser -Filter * -ResultSetSize 25 | Sort-Object Name | Format-Table Name, UserPrincipalName


Step 4 - Changing the UPN Suffix in Bulk
I make the change with 3 commands. The first command does not change any value. It finds the users whose UPN suffix is firatboyan.local and stores them in the $LocalUsers variable. I use the @ sign in the filter deliberately. In this way, if the forest contains a child domain such as sub.firatboyan.local, the users who have the suffix of that domain are not included in the scope.
$LocalUsers = Get-ADUser -Filter "UserPrincipalName -like '*@firatboyan.local'" -Properties UserPrincipalName -ResultSetSize $null
The second command does not make a change yet either. It writes the users that will change in this run to a CSV file, together with their ObjectGUID, current UPN (EskiUPN) and target UPN (YeniUPN) values. I add the date, the time and a random GUID to the file name so that each run has its own file. By default, Export-Csv overwrites a file with the same name without a warning. The -NoClobber parameter prevents this, and -ErrorAction Stop stops the command with an error when the write fails. The path of the file is kept in the $CsvPath variable. I use this file both for the verification in Step 5 and for the rollback in section 5. If writing the CSV file returns an error, I do not continue to the third command.
$CsvPath = "C:\UPN_Degisiklik_$(Get-Date -Format 'yyyyMMdd_HHmm')_$([guid]::NewGuid()).csv"
$LocalUsers | Select-Object ObjectGUID, SamAccountName, @{Name='EskiUPN';Expression={$_.UserPrincipalName}}, @{Name='YeniUPN';Expression={$_.UserPrincipalName -replace '@firatboyan\.local$', '@firatboyan.com'}} | Export-Csv -Path $CsvPath -NoTypeInformation -Encoding UTF8 -NoClobber -ErrorAction Stop
For each user in the variable, the third command replaces the @firatboyan.local part at the end of the UPN with @firatboyan.com and writes the new value to the user object. The UPN prefix stays the same. Because the -replace operator is not case-sensitive, users whose suffix is written as Firatboyan.Local are also changed.
$LocalUsers | ForEach-Object { $newUpn = $_.UserPrincipalName -replace '@firatboyan\.local$', '@firatboyan.com'; Set-ADUser -Identity $_ -UserPrincipalName $newUpn }
This command changes the sign-in name of all users in scope in a single operation. In a production environment, it is necessary to start with a small pilot group first.
The -WhatIf parameter is used to see which objects the command will change without performing a write. The parameter is not added to the end of the command. It is added to the write command inside the braces: Set-ADUser -Identity $_ -UserPrincipalName $newUpn -WhatIf. A -WhatIf written after the closing brace is bound to the ForEach-Object command and returns an error.
When the command succeeds, it does not return any output on the screen. Users whose userPrincipalName attribute is empty are not matched by the filter, so they remain unchanged. If a domain controller with UPN uniqueness checking enabled detects that the target UPN is used by another account, it rejects the write. In this case, the old UPN value of that user is kept.


Step 5 - Verifying the New UPN Values
I run the command from Step 3 again to retrieve the new UPN values of my users. This list is a sample of 25 records and does not show on its own that the change has been completed for all users.
Get-ADUser -Filter * -ResultSetSize 25 | Sort-Object Name | Format-Table Name, UserPrincipalName


To verify that the change has been applied completely, I use the CSV file that I created in Step 4. The command below finds each user in the file by the ObjectGUID value and compares the current UPN value with the YeniUPN value in the file. It lists only the users whose value does not match.
Import-Csv -Path $CsvPath | ForEach-Object { $u = Get-ADUser -Identity $_.ObjectGUID; if ($u.UserPrincipalName -ne $_.YeniUPN) { $u | Select-Object SamAccountName, UserPrincipalName } }
This comparison shows the UPN value that is read at that moment on the domain controller that receives the query. If the verification is performed immediately after the change and the query goes to another domain controller that has not received the replication yet, a user may appear as not matching. For this reason, I either wait for the replication to complete or query the domain controller on which I made the change.
Checkpoint
The comparison command runs without an error and does not list any user. If a user is listed, the UPN that was read does not match the target value. Whether the write command returned an error for this account, and the replication status, must be checked.
4- Changing the UPN Suffix of Users in a Specific Organizational Unit (OU)
In the previous section, I changed the UPN suffix of all users in the domain. If the change has to be made in stages by department, location or pilot group, the same operation can also be applied only to the users in a specific OU. This section is not a continuation of section 3. It is an alternative to it. If all users have already been changed, the filter here does not find any matching user.
Step 6 - Getting the OU DistinguishedName Value
To limit the search to an OU, I need the DistinguishedName value of that OU. I list all OUs in the domain with their name and DistinguishedName values with the command below.
Get-ADOrganizationalUnit -Filter * | Format-Table Name, DistinguishedName -AutoSize

If there are many OUs, the output can be written to a text file with Out-File.
Get-ADOrganizationalUnit -Filter * | Format-Table Name, DistinguishedName -AutoSize | Out-File C:\OrganizationUnits.txt


Format-Table does not produce data. It produces formatting objects that represent the table view. Out-File writes this view as text in the screen layout, so the resulting file is not a CSV file, and long DistinguishedName values that exceed the column width can be truncated. A truncated value cannot be used in the -SearchBase parameter. To get the complete DistinguishedName values, a CSV file is created with the command below.
Get-ADOrganizationalUnit -Filter * | Select-Object Name, DistinguishedName | Export-Csv -Path C:\OrganizationUnits.csv -NoTypeInformation -Encoding UTF8
Step 7 - Listing the Current UPN Values in the OU
I pass the DistinguishedName value of the OU whose UPN suffix I am going to change to the -SearchBase parameter, and retrieve the current UPN values of the users in this OU. By default, -SearchBase also includes the child OUs. To limit the search to the specified OU only, the -SearchScope OneLevel parameter is added to the command.
Get-ADUser -Filter * -SearchBase "OU=Users,OU=IT,OU=Istanbul,OU=Turkey,OU=Europe,DC=firatboyan,DC=local" -ResultSetSize 25 | Sort-Object Name | Format-Table Name, UserPrincipalName

Step 8 - Changing the UPN Suffix of the Users in the OU
The logic of the commands is the same as in Step 4, and the only difference is the -SearchBase parameter. The first command stores only the users in the specified OU whose UPN suffix is firatboyan.local in the $LocalUsers variable.
$LocalUsers = Get-ADUser -Filter "UserPrincipalName -like '*@firatboyan.local'" -SearchBase "OU=Users,OU=IT,OU=Istanbul,OU=Turkey,OU=Europe,DC=firatboyan,DC=local" -Properties UserPrincipalName -ResultSetSize $null
The second command writes the users that will change in this OU to a new CSV file with their old and target UPN values. The file contains only the users in the scope of this run. As in Step 4, the file name contains the date, the time and a GUID, and the -NoClobber and -ErrorAction Stop parameters are used here as well. If writing the CSV file returns an error, I do not continue to the third command.
$CsvPath = "C:\UPN_Degisiklik_$(Get-Date -Format 'yyyyMMdd_HHmm')_$([guid]::NewGuid()).csv"
$LocalUsers | Select-Object ObjectGUID, SamAccountName, @{Name='EskiUPN';Expression={$_.UserPrincipalName}}, @{Name='YeniUPN';Expression={$_.UserPrincipalName -replace '@firatboyan\.local$', '@firatboyan.com'}} | Export-Csv -Path $CsvPath -NoTypeInformation -Encoding UTF8 -NoClobber -ErrorAction Stop
The third command changes the UPN suffix of these users to firatboyan.com.
$LocalUsers | ForEach-Object { $newUpn = $_.UserPrincipalName -replace '@firatboyan\.local$', '@firatboyan.com'; Set-ADUser -Identity $_ -UserPrincipalName $newUpn }

Step 9 - Verifying the New UPN Values
I run the command from Step 7 again to retrieve the new UPN values of the users in the OU.
Get-ADUser -Filter * -SearchBase "OU=Users,OU=IT,OU=Istanbul,OU=Turkey,OU=Europe,DC=firatboyan,DC=local" -ResultSetSize 25 | Sort-Object Name | Format-Table Name, UserPrincipalName

This list is also a sample of 25 records. I verify that all target users in the OU have changed by running the comparison command from Step 5 with the CSV file that I created in Step 8. The replication condition that I described in Step 5 applies here as well.
Import-Csv -Path $CsvPath | ForEach-Object { $u = Get-ADUser -Identity $_.ObjectGUID; if ($u.UserPrincipalName -ne $_.YeniUPN) { $u | Select-Object SamAccountName, UserPrincipalName } }
Checkpoint
The comparison command runs without an error and does not list any user.
5- Effects of the Change and Rollback
A UPN suffix change updates a single attribute on the user object. However, its effect reaches every system that uses that attribute as the sign-in name. To assess the effect correctly, it is necessary to know first what does not change.
What Does Not Change on the On-Premises Side
The sAMAccountName, security identifier (SID) and objectGUID values of the user stay the same. The practical results of this are as follows.
Sign-in in the DOMAIN\user format is not affected. The FIRATBOYAN\user format is based on the sAMAccountName value, and because this value does not change, it continues to work in the same way.
Existing sessions and Kerberos tickets remain valid. Because the tickets are issued to the account itself, the UPN change does not end open sessions. Users do not have to sign out and sign in again, and the tickets do not have to be purged.
File and folder permissions are not affected. NTFS permissions and share permissions store the SID value of the user, not the user name, in the access control list (ACL).
Group memberships and GPO scope are preserved. The member attribute of a group stores its members with distinguished name based links, not with the UPN. As long as the OU of the user, the group memberships and the related filter conditions stay the same, the Group Policy Object (GPO) scope applied to the user also stays the same.
The default UPN in the format sAMAccountName@firatboyan.local remains valid for sign-in after a different UPN is assigned to the user. A user who types this name out of habit can still sign in.
What Is Affected on the On-Premises Side
The places affected by the change are the points that store or process the UPN as text. Credentials saved with the old UPN in Windows Credential Manager, logon scripts that contain the UPN as a fixed value, applications that match the user by UPN, and user certificates that carry the UPN in the Subject Alternative Name field belong to this group. For this reason, applications that depend on the UPN must be tested with a small pilot group before the bulk change.
Effects on the Microsoft Entra ID Side in a Hybrid Environment
If the users are synchronised with Microsoft Entra Connect, the on-premises UPN change is applied to Entra ID in the next sync cycle. The default cycle runs every 30 minutes. When I do not want to wait, I trigger a delta sync manually with the command below. This cmdlet is not in the ActiveDirectory module. It is in the ADSync module that is installed with Microsoft Entra Connect Sync, and it is run on the Microsoft Entra Connect Sync server. Installing RSAT on a management computer does not provide this cmdlet.
Start-ADSyncSyncCycle -PolicyType Delta
For a user that has already been matched, the UPN change does not break the link between the on-premises object and the Entra ID object as long as the configured source anchor stays fixed. The source anchor is mS-DS-ConsistencyGuid in the default configuration, or objectGUID depending on the installation. The only case in which the UPN plays a role in matching is the first synchronisation. At this stage, if the conditions are met, a soft match can be made on the UPN or the primary SMTP address.
Because the user object in Entra ID stays the same, the mailbox, directly assigned licences and static group memberships do not change with this operation. Dynamic groups that use userPrincipalName in the membership rule, however, are evaluated again. The user can be added to these groups or removed from them, so the licences received through a group and the Conditional Access policies applied to the user can change. Before the bulk change, it is necessary to check whether the UPN or the suffix is used in the dynamic group rules in the tenant.
The state of the email address depends on the source of the address. If the primary SMTP address is explicitly defined in the on-premises proxyAddresses attribute, changing the UPN does not change this address. For Exchange Online licensed users whose mail and proxyAddresses attributes are left empty, however, the primary SMTP address is derived from the UPN. If the current primary SMTP address must be preserved independently of the UPN, the address is defined explicitly before the change with the supported Exchange management method of the environment. If the address is intended to continue to be derived from the UPN, this operation is not mandatory.
What changes is the Microsoft 365 sign-in name of the user, and the effects documented by Microsoft are seen in the components that cache this name.
|
Component |
Observed Effect |
Action to Take |
|
Microsoft Authenticator (Android, MFA notification) |
The account continues to appear with the old UPN, and the MFA notification may not arrive. |
Check for notifications is selected in Authenticator and the MFA request is approved. This operation updates the UPN on the account. If it is an allowed method, a verification code can also be used. |
|
Microsoft Authenticator (brokered sign-in) |
In applications that use the broker, repeated sign-in prompts are seen because the name sent by the application does not match the old UPN in the broker. |
The account is removed from Authenticator, and the user signs in again from the application that uses the broker. |
|
Hybrid joined Windows 10 devices |
If the user signs in before the new UPN reaches Entra ID and Conditional Access requires a hybrid joined device, access problems and unexpected restarts can occur. The problem was fixed with the Windows 10 May 2020 update. |
If the problem occurs on a device that does not contain this fix, dsregcmd /leave is run in a Command Prompt opened as administrator on the device, and the device is restarted. After the device joins Entra ID again, the user signs in by selecting the Other user option and typing the new UPN. If Windows Hello for Business is used, it must be registered again. |
|
SaaS and line of business applications |
Applications that match the user by UPN and use Just-in-Time provisioning can create a second profile for the new UPN. |
The applications are tested with pilot users, and automatic provisioning is used if possible. |
|
OneDrive |
The OneDrive URL of the user changes because it contains the UPN. |
Users are informed that shortcuts and links that contain the old URL can be affected. |
|
Teams Meeting Notes (old Wiki-based notes) |
Wiki-based meeting notes created with the old UPN cannot be accessed through Teams. |
The notes are downloaded from the My files, Microsoft Teams Data, Wiki path in OneDrive. Current Loop-based notes are not stored in this folder. They are stored in the Meetings folder, which is in OneDrive for private meetings and on the related SharePoint site for channel meetings. |
Rollback
On the Active Directory side, the rollback consists only of writing the old UPN values back to the user objects. For this, I use the CSV file that I created in Step 4 or Step 8. The {CSV File Name} part in the command must be replaced with the full name, including the extension, of the file created in the run that is going to be rolled back.
The command below looks only at the users in this file and finds each of them by the ObjectGUID value. If the current UPN value of the user is still equal to the YeniUPN value in the file, it writes the EskiUPN value back. If the current value does not match the target value, the command does not change this account and lists it on the screen for review. For such an account, the first write may have failed, the account may have been changed separately afterwards, or the query may have gone to a domain controller where replication has not completed.
Import-Csv -Path "C:\{CSV File Name}" | ForEach-Object { $u = Get-ADUser -Identity $_.ObjectGUID; if ($u.UserPrincipalName -eq $_.YeniUPN) { Set-ADUser -Identity $u -UserPrincipalName $_.EskiUPN } else { $u | Select-Object SamAccountName, UserPrincipalName } }
In a hybrid environment, a rollback means that the UPN is calculated again with the same rules on the Entra ID side. If the cloud sign-in name changes, the users experience the effects in the table above once more.
If the added UPN suffix has to be removed from the forest, it must first be confirmed that no user is using this suffix.
This article covered adding the firatboyan.com UPN suffix to the firatboyan.local forest and moving the UPN values of the users to this suffix with PowerShell, first across the domain and then within a specific organizational unit (OU). If all accounts in the CSV file created before the change have been queried without an error and the comparison has not listed any user, the operation on the Active Directory side is complete. In a hybrid environment, it must also be verified that the new UPN values appear in Microsoft Entra ID after the sync.
I hope you find it useful...
Feel free to share your thoughts and questions about this article in the comments below. Every contribution helps the content reach more people and makes for a more useful discussion.