Update: Be aware, this script has not been tested with SIP, X400 or other address types. I am working on an update to validate these scenarios, but in the meantime, proceed at your own risk with these address types.
I recently encountered a question in an online forum where someone asked for a script to convert all of their user’s email addresses to lower case values. While this doesn’t affect the message delivery, it can have an impact on aesthetics when the address is displayed in an external recipient’s email client. An Exchange Email Address Policy can do this to some degree, but I wanted to see how it could be done with PowerShell.
The challenge with a script like this is twofold:
- Email addresses (proxy addresses) are a multi-valued attribute, which can be tricky to work with.
- PowerShell is generally not case-sensitive, and therefore when we try to rename Mr. Gallalee’s email address in the screenshot below, we can see that it does not work:
After a little bit of inspiration from a script written by Michael B Smith, I came up with the below:
$MailboxList = Get-Mailbox -ResultSize unlimited $MailboxList | % { $LoweredList = @() $RenamedList = @() foreach ($Address in $_.EmailAddresses){ if ($Address.prefixstring -eq "SMTP"){ $RenamedList += $Address.smtpaddress + "TempRename" $LoweredList += $Address.smtpaddress.ToLower() } } Set-mailbox $_ -emailaddresses $RenamedList -EmailAddressPolicyEnabled $false Set-mailbox $_ -emailaddresses $LoweredList #Without this line the "Reply To" Address could be lost on recipients with more than one proxy address: Set-mailbox $_ -PrimarySmtpAddress $_.PrimarySmtpAddress }
This script works as follows:
- Puts all mailboxes into the $MailboxList variable. If you don’t want all mailboxes, edit the Get-Mailbox cmdlet as you see fit.
- Filters out X400 and other non-SMTP addresses.
- Creates an array called $RenamedList which stores each proxy address with “TempRename” appended to it (e.g. Rgallalee@demolab.localTempRename).
- Creates another array ($LoweredList) and use the “ToLower” method on each proxy address.
- Sets the proxy address for the user to the value of $RenamedList and then to $LoweredList.
- This is how we get around the case case insensitivity – name it to something else and then name it back.
- Step 4 and 5 don’t preserve the “Primary” / “Reply-To” address, so we set it back manually with the last line.
Note: This script turns off the email address policy for each user.
As always, feedback is welcome.
EDIT Dec 2018:
This is a similar approach, but for mailboxes migrated to Office 365. In this case, only the Primary SMTP addresses are targeted.
It may also be faster than the above, due to the fact we’re only operating against mailboxes that have uppercase (vs all of them).
Set-ADServerSettings -ViewEntireForest:$true $TargetObjects = Get-RemoteMailbox -ResultSize Unlimited | Where {$_.PrimarySmtpAddress.ToLower() -cne $_.PrimarySmtpAddress} Write-Host $TargetObjects.count "Remote mailboxes have one or more uppercase characters." -ForegroundColor Cyan #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 Write-Host $Counter = $TargetObjects.Count foreach ($RemoteMailbox in $TargetObjects) { Write-Host "Setting: " -ForegroundColor DarkCyan -NoNewline Write-Host $RemoteMailbox.PrimarySmtpAddress -ForegroundColor Cyan Write-Host "Remaining: " -ForegroundColor DarkCyan -NoNewline Write-Host $Counter -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)} $Counter -- } Write-Host Write-Host "Done." -ForegroundColor DarkCyan #End
That script is cool. Ran it so the auto signatures of Exclaimer could work. Thanks
I know this post/reply is SUPER old, however if others stumble upon this issue in the future, in Exclaimer Cloud you can now using the built in formatting options to force the email address output to be all lower-case in the signature.
Thanks for stopping by!
Thanks Mike, this looks like it will do excactly what our Director wants done to our 1800+ address’. Before I run this against our environment is there a way I can test it on a couple of accounts forst? I’m thinking by adding the account after Get-Mailbox and removing the resultsize I should be able to run it against one account.
The script works against users in $mailboxlist. So you can use -resultsize 10 and this will test against only 10 users.
Great stuff. Thanks; works a treat
Mike, Thanks for the script. It worked as advertised on a sample Get. One side effect though was it removed X400 and sip addresses. Did I miss something or is there a way to keep that from happening.
This hasn’t been tested, but maybe try something like this:
$MailboxList = Get-Mailbox -ResultSize unlimited
$MailboxList | % {
$LoweredList = @()
$RenamedList = @()
$NonSMTPAddresses = @()
foreach ($Address in $_.EmailAddresses){
if ($Address.prefixstring -ne “SMTP”) {$NonSMTPAddresses += $Address}
if ($Address.prefixstring -eq “SMTP”){
$RenamedList += $Address.smtpaddress + “TempRename”
$LoweredList += $Address.smtpaddress.ToLower()
}
}
Set-mailbox $_ -emailaddresses ($RenamedList + $NonSMTPAddresses) -EmailAddressPolicyEnabled $false
Set-mailbox $_ -emailaddresses $LoweredList
#Without this line the “Reply To” Address could be lost on recipients with more than one proxy address:
Set-mailbox $_ -PrimarySmtpAddress $_.PrimarySmtpAddress
}
Hi All, Just in case anyone finds this wondering on how to keep their x500 and x400 addresses which are extremely important if you have migrated users from other servers etc. I have adjusted the script and posted below to also include X500 and X400 addresses. Ran this over a 500 user exchange server and all OK 🙂 happy days.
$MailboxList = Get-Mailbox
$MailboxList | % {
$LoweredList = @()
$RenamedList = @()
$NonSMTPAddresses = @()
foreach ($Address in $_.EmailAddresses){
if ($Address.prefixstring -eq “X400”) {$NonSMTPAddresses += “X400:” + $Address.addressstring}
if ($Address.prefixstring -eq “X500”) {$NonSMTPAddresses += “X500:” + $Address.addressstring}
if ($Address.prefixstring -eq “SMTP”){
$RenamedList += $Address.smtpaddress + “TempRename”
$LoweredList += $Address.smtpaddress.ToLower()
}
}
echo $LoweredList
echo $RenamedList
echo $NonSMTPAddresses
Set-mailbox $_ -emailaddresses ($RenamedList + $NonSMTPAddresses) -EmailAddressPolicyEnabled $false
Set-mailbox $_ -emailaddresses ($LoweredList + $NonSMTPAddresses)
#Without this line the “Reply To” Address could be lost on recipients with more than one proxy address:
Set-mailbox $_ -PrimarySmtpAddress $_.PrimarySmtpAddress
}