Change User Principal Name equals Email Address automation 

Refer Linke for Detailed Explanation with screenshot

For Autodiscover  to work properly in On premises and Exchange Online , We need email and User principal name to match. Every time IT admin cannot keep checking this its tiring to do it manually.

Its better to run it on a task scheduler so that it maintains the UPN and Email to be same for the ones which is not matching.

Supported on Exchange 2013 or above | Premise or Exchange Hybrid Server

NOTE : Before running the script run below commands to check which are the mailboxes it will apply to


Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Primarysmtpaddress -ne $_.UserPrincipalname}



Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Primarysmtpaddress -ne $_.UserPrincipalname} | ForEach-Object {Set-Mailbox $_.identity -UserPrincipalName $_.Primarysmtpaddress -whatif}

To use Task Scheduler

Create Basic Task

Choose Daily

Set a time

Start a Program

Made to stop the task if it exceeds 4 hours


# Include Exchange Powershell Module 
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn 
#Lists All Mailboxes 
#Checks Email and UPN are same 
#Lists which are not email 
#Applies UPN Matching email 
Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Primarysmtpaddress -ne $_.UserPrincipalname} | ForEach-Object {Set-Mailbox $_.identity -UserPrincipalName $_.Primarysmtpaddress} 
# Exit Exchange Powershell Module 
Remove-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn