Converting email addresses to lowercase in Exchange Online/Hybrid

Exchange logo

How to convert existing primary email addresses to lowercase, as well as ensuring that any new mailboxes also have lowercase primary email address.

You may want to make sure your users have their email addresses in lower case. This can be useful for the following reasons:

  1. It just looks tidier, in Exchange/AD but also in Outlook when users view users details in the address book.
  2. You may have applications that are using email address for SSO (can can’t use UPN for whatever reason and you haven’t been able to match email and UPN), but are also case sensitive (e.g. Salesforce).

So we need to do 2 things:

  1. Edit the email address policy in Exchange to ensure that all new users will have lowercase email.
  2. Convert email addresses for existing mailboxes.

Unfortunately it is not possible to edit the email address policies in Exchange Online, because they don’t actually do anything.

However, if you still have on-prem AD, and therefore you should have an Exchange Hybrid server for mailbox creation and management, you can set the policy there (you should be using that to create all your Exchange Online mailboxes anyway).

Disclaimer: you may have issues with users having to reauthenticate on mobile, or recreate their Outlook profiles. Test these changes first before wider deployment.

First, check your email address policies, you may well just have the default policy as below:

 Get-EmailAddressPolicy | select Name,EnabledPrimarySMTPAddressTemplate 

Now, we’ll update this to be the same format (first.last) but in lowercase:

Set-EmailAddressPolicy -Identity "Default Policy" -EnabledPrimarySMTPAddressTemplate ""

Note: you can see what variables are available here:

Now when you create a user, it will all be in lowercase:

Machine generated alternative text:
Michael Sawyer 
mailbox usage 
contact information 
email address 
mailbox features 
member of 
Mail Tip 
mailbox delegation 
Each email address type has one default reply address. 
The default reply address is displayed in bold. To 
change the default reply address, select the email 
address that you want to set as the default, and then 
double-click to edit it. 
Email address: 

Next, we need to convert existing users. Since Exchange does not differentiate between upper and lower case. Use the following script for remote (Exchange Online) mailboxes, connecting to your on-prem Exchange server first (modified from

Note that the only impact we found in a live environment for several hundred users, was that users of iOS mail would be prompted for their password again. Outlook on desktop or mobile was unaffected.

# Script converts the primary email address to lowercase

$ErrorActionPreference = "SilentlyContinue"

#Connect to Exchange 2016

$OU = "OU=Users,DC=domain,DC=com"
$ADusers = Get-ADUser -Filter 'enabled -eq $true' -SearchBase $OU -properties Mail | sort-object Mail
$count = $ADusers.count
Write-Host "$count enabled users in the OU:" -ForegroundColor Cyan
foreach ($user in $ADusers){$user.Mail}

$TargetObjects =@()

foreach ($user in $ADusers) {
$TargetObject = Get-RemoteMailbox -Identity $user.samaccountname | Where {$_.PrimarySmtpAddress.ToLower() -cne $_.PrimarySmtpAddress} # To get just one user
if ($TargetObject) {
$TargetObjects += $TargetObject}
if (!$TargetObjects) {
    write-host "No mailboxes found with uppercase characters, exiting" -ForegroundColor yellow
} else {
    write-host "Total mailboxes with uppercase characters:" $TargetObjects.count
    write-host "Selecting the first 30"
        $TargetObjects = $TargetObjects | select -first 30
$count = $TargetObjects.count
Write-Host "The following $count mailboxes have uppercase characters in PrimarySmtpAddress and will be converted" -ForegroundColor Cyan
Read-host -prompt "Press any key to continue or CTRL+C to quit"

#Backup First
Function Get-FileFriendlyDate {Get-Date -format ddMMMyyyy_HHmm.s}
$DesktopPath = ([Environment]::GetFolderPath("Desktop") + '\')
$LogPath = ($DesktopPath + (Get-FileFriendlyDate) + "-UppercaseBackup.xml")
$TargetObjects | select DistinguishedName, PrimarySMTPAddress, EmailAddresses | Export-Clixml $LogPath
Write-Host "A backup XML has been placed here:" $LogPath -ForegroundColor Cyan
$Counter = $TargetObjects.Count
foreach ($RemoteMailbox in $TargetObjects) {
    Write-Host "Old address: " -ForegroundColor DarkCyan -NoNewline
    Write-Host $RemoteMailbox.PrimarySmtpAddress -ForegroundColor Cyan
    Write-Host "New address: " -ForegroundColor DarkCyan -NoNewline
    Write-Host $RemoteMailbox.PrimarySmtpAddress.ToLower() -ForegroundColor Cyan
    Set-RemoteMailbox $RemoteMailbox.Identity -PrimarySmtpAddress ("TMP-Rename-" + $RemoteMailbox.PrimarySmtpAddress) -EmailAddressPolicyEnabled $false
    Set-RemoteMailbox $RemoteMailbox.Identity -EmailAddresses @{remove = $RemoteMailbox.PrimarySmtpAddress}
    Set-RemoteMailbox $RemoteMailbox.Identity -PrimarySmtpAddress $RemoteMailbox.PrimarySmtpAddress.ToLower()
    Set-RemoteMailbox $RemoteMailbox.Identity -EmailAddresses @{remove = ("TMP-Rename-" + $RemoteMailbox.PrimarySmtpAddress)}

    Set-RemoteMailbox $RemoteMailbox.Identity -EmailAddressPolicyEnabled $true

Write-Host "Done." -ForegroundColor DarkCyan


Posted in Exchange Online, Office 365

Related Posts

Leave a Reply

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

%d bloggers like this: