none
Adding a new alias and setting it as primary email address

    Question

  • Hello,

    I have to add some aliases to existing <g class="gr_ gr_289 gr-alert gr_gramm gr_run_anim gr_inline_cards Style multiReplace" data-gr-id="289" id="289" style="font-size:0.75em;">mailbox  in</g> exchange 2010 environment.

    Some have already multiple aliases configured.

    I am able to add the new aliases via script with PowerShell

    but if I try to set the new alias as default mail address I loose the other.

    There is a way of accomplishing this task using a <g class="gr_ gr_224 gr-alert gr_spell gr_run_anim gr_inline_cards ContextualSpelling ins-del multiReplace" data-gr-id="224" id="224">csv</g> file as an import source?

    Thanks a lot


    Luca Pozzoli

    Monday, March 20, 2017 6:42 PM

Answers

  • If you want to add a new reply address, then just do Set-Mailbox with -PrimarySMTPAddress set to that address.  The existing PrimarySMTPAddress will be made a proxy address.  There's no need to mess with EmailAddresses in this case.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Tuesday, March 21, 2017 1:02 AM
    Moderator

All replies

  • This assumes you have a CSV with headers

    SamAccountName

    EmailAddress

    $Content = Import-CSV -Filepath <>

    Foreach ($Person in $Content)

    {

    $Addresses = Get-mailbox -Identity $person.samaccountname | select -expandproperty emailaddresses

    $Addresses = $Addresses.Replace('SMTP:','smtp:')

    Set-Mailbox -Identity $person.samaccountname -EmailAddresses "SMTP:$($person.emailaddress)",$addresses

    Clear-variable Addresses

    }


    Monday, March 20, 2017 6:58 PM
  • Thank you very much, Adam,

    unfortunately, when I execute the script I receive the following error

    Method invocation failed because [System.Object[]] doesn't contain a method named 'Replace'.
    At C:\Script\ManageAlieases\new2.ps1:9 char:32
    + $Addresses = $Addresses.Replace <<<< ('SMTP:','smtp:')
        + CategoryInfo          : InvalidOperation: (Replace:String) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound


    Have I missed something?

    cheers


    Luca Pozzoli

    Monday, March 20, 2017 8:53 PM
  • No you haven't syntax is part of the process. I find these nest AD properties troublesome on occassion

    Try what I've written below.

    $Content = Import-CSV -Filepath <>

    Foreach ($Person in $Content)

    {

    $Addresses = $Addresses.Replace('SMTP:','smtp:')

    $Addresses += "SMTP:$($person.emailaddress)"

    Set-Mailbox -Identity $person.samaccountname -EmailAddresses $addresses

    Clear-variable Addresses

    }

    Monday, March 20, 2017 9:09 PM
  • If you want to add a new reply address, then just do Set-Mailbox with -PrimarySMTPAddress set to that address.  The existing PrimarySMTPAddress will be made a proxy address.  There's no need to mess with EmailAddresses in this case.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Tuesday, March 21, 2017 1:02 AM
    Moderator
  • Hi,

    Several points we should understand first:

    • One mailbox can only have one 'Alias'
    • One mailbox can only have one default reply address (Primary SMTP address)
    • One mailbox can have multiple email addresses in address list.
    • We cannot have multiple alias as defaults mail addresses.
    • If Email Address Policy is enabled on mailbox, Primary SMTP address will be automatically updated based on Email Address Policy.

    So what's your propose now? 


    Best Regards,

    Lynn-Li
    TechNet Community Support


    Please remember to mark the replies as answers.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, March 21, 2017 3:13 AM
    Moderator
  • Hi, thank you for all this precious answer.

    You are right I explain the issue better.

    for an assessment process, I have to create new ou that <g class="gr_ gr_34 gr-alert gr_gramm gr_run_anim gr_inline_cards Grammar multiReplace" data-gr-id="34" id="34">match</g> the company social structure (my company is a holding)

    So I create Ou company A and company B company C and so on.

    Now all the user have to be moved from the actual Ou to the new one.

    They have already a primary email address and a lot of other secondary email addresses.

    When the user will be moved to the new OU they have to set the corresponding email address (if they haven't it yet)

    and set it as the default address.

    Furthermore, when a user change the company ( from company A to company B for instance ) they have to change the email address accordingly.

    I suggest HR department use mail address policy but they want to use custom script that will be fed by HR system


    Luca Pozzoli

    Tuesday, March 21, 2017 8:01 AM
  • Thank you so much, Ed, I use your suggestion to accomplish my task

    I use the first statement to set the new email address to the mailboxes involved and your tips to setting as default address without destroying the others

    Import-Csv C:\Script\ManageAlieases\basealias.csv |ForEach {Set-mailbox -Identity $_.samaccountname -EmailAddresses @{Add= $_.userprincipalname}}
    Import-Csv C:\Script\ManageAlieases\basealias.csv |ForEach {Set-mailbox -Identity $_.samaccountname -PrimarySMTPAddress $_.userprincipalname}




    I will schedule a second job that deletes all address except the primary 

    Import-Csv C:\Script\ManageAlieases\basealias.csv |ForEach {Set-mailbox -Identity $_.samaccountname -EmailAddresses $_.userprincipalname}




    Luca Pozzoli

    Tuesday, March 21, 2017 10:32 AM
  • You're welcome.  Happy to have helped.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Wednesday, March 22, 2017 2:52 AM
    Moderator