Converting SMTP Proxy Addresses to Lowercase

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:

  1. Email addresses (proxy addresses) are a multi-valued attribute, which can be tricky to work with.
  2. 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:

WARNING: The command completed successfully but no settings of 'demolab.local/Users/Rob Gallalee' have been modified.

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:

  1. Puts all mailboxes into the $MailboxList variable.  If you don’t want all mailboxes,  edit the Get-Mailbox cmdlet as you see fit.
  2. Filters out X400 and other non-SMTP addresses.
  3. Creates an array called $RenamedList which stores each proxy address with “TempRename” appended to it (e.g. Rgallalee@demolab.localTempRename).
  4. Creates another array ($LoweredList) and use the “ToLower” method on each proxy address.
  5. Sets the proxy address for the user to the value of $RenamedList and then to $LoweredList.
    1. This is how we get around the case case insensitivity – name it to something else and then name it back.
  6. 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.

7 thoughts on “Converting SMTP Proxy Addresses to Lowercase

  1. 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.

  2. 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
      }

  3. 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

    }

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s