Manually Configuring Email Addresses for Exchange Server 2013 Recipients using PowerShell

Managing email addresses for a mailbox is a good learning experience for dealing with multi-value attributes in PowerShell.

A mailbox can have multiple email addresses, for example where a company has rebranded and changed their primary email addresses to a new name, but still wish to keep receiving any emails sent to the old email addresses.

Another example is a person who has a name that is very long or easy to misspell. In these cases you can add a secondary address that is shorter or easier to spell to the mailbox.

Here is the current email address for my test mailbox. At the moment it has just one email address.

[PS] C:\>Get-Mailbox Paul.Cunningham | Select-Object EmailAddresses

EmailAddresses
--------------
{SMTP:paul.cunningham@exchange2013demo.com}

We’ve already looked at some examples of using Set-Mailbox to manage mailboxes. So you might go ahead and use it to add an email address to a mailbox like this.

[PS] C:\>Set-Mailbox Paul.Cunningham -EmailAddresses paulc@exchange2013demo.com

WARNING: Couldn't update the primary SMTP address because this mailbox is configured
to use an email address policy. To disable the email address policy for this mailbox,
run the command with the EmailAddressPolicyEnabled parameter set to $false.

The command fails because the mailbox has an email address policy applied to it. Following the suggestion in the warning message we can go ahead and disable the email address policy to be able to make the change to the mailbox.

[PS] C:\>Set-Mailbox Paul.Cunningham -EmailAddresses paulc@exchange2013demo.com -EmailAddressPolicyEnabled $false

This time no errors or warnings were returned. Let’s take a look at the result.

[PS] C:\>Get-Mailbox Paul.Cunningham | Select-Object EmailAddresses

EmailAddresses
--------------
{SMTP:paulc@exchange2013demo.com}

Whoops! Instead of adding an extra email address, the original email address has been overwritten. Let’s revert back to the original configuration and try again.

[PS] C:\>Set-Mailbox Paul.Cunningham -EmailAddresses paul.cunningham@exchange2013demo.com -EmailAddressPolicyEnabled $true

[PS] C:\>Get-Mailbox Paul.Cunningham | Select-Object EmailAddresses

EmailAddresses
--------------
{SMTP:paul.cunningham@exchange2013demo.com}

Now let’s explore this concept of multi-value attributes a little more. Here is a mailbox that already has multiple email addresses assigned to it.

[PS] C:\>Get-Mailbox Robert.Henderson | Select-Object EmailAddresses

EmailAddresses
--------------
{smtp:rob.henderson@exchange2013demo.com, SMTP:Robert.Henderson@exchange2013demo.com}

Using Get-Member we can see that the EmailAddresses attribute is a collection.

[PS] C:\>Get-Mailbox Robert.Henderson | Get-Member EmailAddresses

   TypeName: Microsoft.Exchange.Data.Directory.Management.Mailbox

Name           MemberType Definition
----           ---------- ----------
EmailAddresses Property   Microsoft.Exchange.Data.ProxyAddressCollection EmailAddresses

We can also expand the collection to see more details about each individual entry. Notice differences such as IsPrimaryAddress, and the ability to have a Prefix (i.e. for address types other than SMTP).

[PS] C:\>Get-Mailbox Robert.Henderson | Select-Object -ExpandProperty EmailAddresses

SmtpAddress        : rob.henderson@exchange2013demo.com
AddressString      : rob.henderson@exchange2013demo.com
ProxyAddressString : smtp:rob.henderson@exchange2013demo.com
Prefix             : SMTP
IsPrimaryAddress   : False
PrefixString       : smtp

SmtpAddress        : Robert.Henderson@exchange2013demo.com
AddressString      : Robert.Henderson@exchange2013demo.com
ProxyAddressString : SMTP:Robert.Henderson@exchange2013demo.com
Prefix             : SMTP
IsPrimaryAddress   : True
PrefixString       : SMTP

When we used Set-Mailbox in the earlier example it overwrote the existing attribute with the new value, rather than insert or append the new value to the existing one.

To get the desired result we need to use different syntax. Don’t worry, it isn’t difficult at all.

[PS] C:\>Set-Mailbox Paul.Cunningham -EmailAddresses @{Add='paulc@exchange2013demo.com'}

It’s as simple as that. Here is the result. The email address policy is still applying the primary email address of paul.cunningham@exchange2013demo.com, but the shorter address of paulc@exchange2013demo.com has been added as well.

[PS] C:\>Get-Mailbox Paul.Cunningham | Select-Object -ExpandProperty EmailAddresses

SmtpAddress        : paulc@exchange2013demo.com
AddressString      : paulc@exchange2013demo.com
ProxyAddressString : smtp:paulc@exchange2013demo.com
Prefix             : SMTP
IsPrimaryAddress   : False
PrefixString       : smtp

SmtpAddress        : paul.cunningham@exchange2013demo.com
AddressString      : paul.cunningham@exchange2013demo.com
ProxyAddressString : SMTP:paul.cunningham@exchange2013demo.com
Prefix             : SMTP
IsPrimaryAddress   : True
PrefixString       : SMTP

Want to remove an address instead? Just as easy.

[PS] C:\>Set-Mailbox Paul.Cunningham -EmailAddresses @{Remove='paulc@exchange2013demo.com'}

In the example above the primary email address for the mailbox has remained the same and additional email addresses have been added or removed.

If you need to change the primary email address for the mailbox instead, then there is a slightly different approach used.

First you need to disable email address policies for the mailbox. Don’t worry; this does not remove any of the email addresses that the policy has already added.

[PS] C:\>Set-Mailbox Paul.Cunningham -EmailAddressPolicyEnabled $false

Next we need to use Set-Mailbox and provide the entire set of email addresses that we want to exist on the mailbox, using the case-sensitive prefix “SMTP” to specifiy which one is the primary address.

[PS] C:\>Set-Mailbox Paul.Cunningham -EmailAddresses SMTP:paulc@exchange2013demo.com,smtp:paul.cunningham@exchange2013demo.com

Let’s take one last look at the results.

[PS] C:\>Get-Mailbox Paul.Cunningham | Select-Object -ExpandProperty EmailAddresses

SmtpAddress        : paul.cunningham@exchange2013demo.com
AddressString      : paul.cunningham@exchange2013demo.com
ProxyAddressString : smtp:paul.cunningham@exchange2013demo.com
Prefix             : SMTP
IsPrimaryAddress   : False
PrefixString       : smtp

SmtpAddress        : paulc@exchange2013demo.com
AddressString      : paulc@exchange2013demo.com
ProxyAddressString : SMTP:paulc@exchange2013demo.com
Prefix             : SMTP
IsPrimaryAddress   : True
PrefixString       : SMTP

As you can see the paulc@exchange2013demo.com email address was added to the mailbox and was made the primary email address as well.

Comments

  1. Tunde says

    Thanks, Paul. I feel really silly reading this article because I thought, Ohh…I know how to do all this, then I saw that simple @{Add=”SmtpAddress’}. I never knew I could objects to arrays like that. Here is the same of how I’ve been doing similar thing.
    ———————
    $OwnerMailbox = Get-Mailbox $Owner
    $UserMailbox = Get-Mailbox $User
    $OwnerMailbox.GrantSendOnBehalfTo += $UserMailbox.DistinguishedName
    Set-Mailbox $OwnerMailbox.alias -GrantSendOnBehalfTo $OwnerMailbox.GrantSendOnBehalfTo
    ——————–

    All that replaced by one simple expression.
    Thanks again!!!

  2. Petemoss007 says

    I have the exact scenario you mentioned at the beginning. A company with many users all with more than one email address. The company is rebranding from CompanyA to CompanyB. So I need a powershell command to check all users and, if they have an email ending in @companyA.com that is set to the primary, I need to add that user an email address ending in @companyB.com and make it the primary while leaving all the existing email addresses in place.

  3. Petemoss007 says

    My issue is that these users are in multiple OU’s, multiple departments, etc. If I could setup a new policy and have a custom attribute that says “if the users primary email ends in @companA.com” then it would work. But I have to find all the users in all the OU’s with a primary email address ending in @companyA.com and add a new email address and make it primary.

    When I looked at custom attributes I did not see where I could specify anything like the above.

    Also, thank you so much for trying to help me with this.

    • says

      Read the article I linked to above, particularly the PowerShell example towards the end. You can use -RecipientFilter to be as broad or as specific as you need to.

      If you’d rather just write a script that’s fine, I’m just suggesting email address policies may be another solution for you.

  4. Petemoss007 says

    I’ll look at the script. I’d prefer to use an email policy but since I cannot specify applying it to only the people with a specific domain name in their primary email address, I will probably have to use the script somehow.

  5. Saul Nolasco says

    Paul,

    Hopefully you are still reading this comment thread. Is there a way to set that parameter to false at a global level? Doing it for all of the mailboxes, This has been causing issues for some of my users and I have +500 to take care of. Doing one by one can get a bit tedious.

    Thanks

  6. Courtney says

    Hi Paul,

    We used to be on Exchange 2003 where Recipient Policies controlled the Email address policy. Many of our older mailboxes have multiple email addresses that I need to remove. I can search the EmailAddresses multi-value field for the mailboxes that have that email domain that we don’t use, but I don’t know how to remove them. Since the Recipient Policy created them all, they are all created with the following format “alias@old.emaildomain.com”. How would I script it using a variable for alias? Sorry, I’m doing great with CMDLETs but haven’t scripted much.

    Thanks so much!

  7. Courtney says

    Wait, Could I just do the following?
    get-mailbox -resultsize unlimited |Set-Mailbox -EmailAddresses @{Remove=’*@old.emaildomain.com’}

    Thanks!

  8. Rene says

    Hello,

    I have several users with multiple e-mail addressen, I would like to change there primary addresses but when i set a new default email adresses the other addresses are deleted.
    I only need to change the Isprimary flag but I can’t it tells me that it’s readonly

    Is there a simple way of doing this ?

  9. MHD says

    Hello dear,
    I have a question about Ms -Exchange 2013, hope you can help me about that.
    i have a distribution group named “support”, toe people (sam, mike) are member of group.
    they both receive any email had sent to this group.
    it is important that all their outgoing email send by support account ,not their own account.
    they only solution that i khnow is using “send As permission” but we are not sure they do this every time that they want send email.
    is there any other reliable solution for that?
    i really really appreciative your time and help.
    Thank you in advance.
    MHD

  10. Hans Peeters says

    Hello,

    We need to change primary email address for most of our 2500 mailboxes. For specific reasons we connot use Email Address Policies, we need to use powershell.
    At the end of this article we have found the powershell command.
    All working fine in lab.
    However we noticed that other types of addresses like SIP and X400 disappear.

    How can we change primary smtp address by keeping SIP and X400 address of mailbox?

    Regards
    Hans

  11. Lars Panzerbjørn says

    Thanks for the article :-)

    I am trying to add an email address and make it the Primary SMTP Address, but without having to copy out all the other addresses first, but I can’t really figure out how to do it.

    I tried:
    Set-Mailbox -Identity $Alias -EmailAddresses @{add=’smtp:panzer@bjrn.com’}

    But that doesn’t seem to do the trick. It just adds the address.

    Is what I’d like to do even possible?

    • says

      Read the part of the article that starts with “If you need to change the primary email address for the mailbox instead, then there is a slightly different approach used.”

  12. Carl Frank says

    Paul,

    Great Stuff!

    Question: We just migrated 450 mailboxes from on prem exchange 2010 to O365 Enterprise and, in the cloud the mailbox email addresses have all applied the UPN as the SIP address. This is breaking the functionality between Outlook and Lync as the Default SMTP addresses in most cases are not the same as the UPN.

    I tested by adding SIP addresses to the proxy attribute for a few accounts on premises and after running dirsync, they are now correct in the cloud. Currently there are no SIP addresses on premises, so I am trying to identify a way to create a SIP address that mirrors the default SMTP address in bulk on the Exchange 2010 side.
    Any thoughts would be appreciated. I aqm getting up to speed on Powershell, but still quite a novice.
    Thanks,

  13. JP O Leary says

    Hi Paul,

    The article above is very good.

    What powershell script would I use to delete a specific smtp address from all users in a domain?

    For example I want to delete all smtp address ending in source.local or target.local.

    Thanks

    JP

Leave a Reply

Your email address will not be published. Required fields are marked *