none
PowerShell script to add new SMTP address as primary address RRS feed

  • Question

  • Hello,

    I am looking for a PowerShell script to add new SMTP address as primary address for 2000 users and do not touch existing SMTP and X.500 addresses. Exchange server version is 2007 with SP3

    Can someone help ?


    Karthik R

    Monday, January 21, 2013 10:24 PM

Answers

  • If you want to do that with PowerShell command, this is an example:

    Create one csv file to included all the needed information(Name and emailaddress), then run this command to add the email address and set it as primary email address:

    Import-Csv c:\data.csv | Foreach{
    $maileg = Get-Mailbox -Identity $_.Name
    $maileg.EmailAddresses += $_.emailaddress
    $maileg | Set-Mailbox -EmailAddresses $maileg.EmailAddresses -PrimarySmtpAddress $_.emailaddress
     
    }

    Thanks,

    Evan Liu

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tnmff@microsoft.com


    Evan Liu
    TechNet Community Support

    • Marked as answer by RKART Saturday, January 26, 2013 3:49 PM
    Tuesday, January 22, 2013 12:49 PM

All replies

  • Hi,
    Any special reason why you are not considering creating a new Email Address Policy to do the job?
    That would be the recommended way and it would not remove any existing SMTP or X500 addresses.

    Managing E-Mail Address Policies
    http://technet.microsoft.com/en-us/library/aa998940(v=exchg.80).aspx

    Martina Miskovic

    Tuesday, January 22, 2013 4:44 AM
  • Hi,

    The primary SMTP is going to be shared address with parent company so there may be email address conflict if I use Email address policy. I will be receiving email address list from parent company, which need to be stamped at our end.


    Karthik R

    Tuesday, January 22, 2013 6:28 AM
  • If you want to do that with PowerShell command, this is an example:

    Create one csv file to included all the needed information(Name and emailaddress), then run this command to add the email address and set it as primary email address:

    Import-Csv c:\data.csv | Foreach{
    $maileg = Get-Mailbox -Identity $_.Name
    $maileg.EmailAddresses += $_.emailaddress
    $maileg | Set-Mailbox -EmailAddresses $maileg.EmailAddresses -PrimarySmtpAddress $_.emailaddress
     
    }

    Thanks,

    Evan Liu

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tnmff@microsoft.com


    Evan Liu
    TechNet Community Support

    • Marked as answer by RKART Saturday, January 26, 2013 3:49 PM
    Tuesday, January 22, 2013 12:49 PM
  • Hi Evan,

    I looking same kind of powershell script what you have done. I need to add new smtp address for users and set that new email address as primary email address. Old primary smtp address should stay as secondary email address to users.

    I using Exchange 2010 Sp1 and that code did not work.

    I have in my CSV file

    Name,Emailaddress

    Test.user1,Test.user1@newdomain.com

    Have I written that csv file information wrong?

    Thank you in advanced.

    Br,

    Satu

    Sunday, May 5, 2013 3:55 PM
  • On Sun, 5 May 2013 15:55:01 +0000, SatuS wrote:
     
    >I looking same kind of powershell script what you have done. I need to add new smtp address for users and set that new email address as primary email address. Old primary smtp address should stay as secondary email address to users.
     
    Why not use an Email Address Policy to do that?
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Sunday, May 5, 2013 7:54 PM
  • Hi Evan, 

    i am trying to add another SMTP address on the existing user. i dont want to make new email address as primary. to do this i am using below script, is it correct ? as i am not getting any error after executing this script and there is not result also.. am using exchange 2010. 

    Import-Csv c:\data.csv | Foreach{
    $maileg = Get-Mailbox -Identity $_.Name
    $maileg.EmailAddresses += $_.emailaddress

    }


    srini

    Thursday, September 26, 2013 3:35 AM
  • Hi Sriniva,

    I replied  to you in other thread .

    http://social.technet.microsoft.com/Forums/exchange/en-US/89a8d128-c8d9-4ee8-8219-f33acb9b2da7/script-to-add-another-email-address-for-the-existing-users


    If you found my post helpful, please give it a Helpful vote. If it answered your question, remember to mark it as an Answer. ---------- MCITP - Exchange 2010 | MCITP - Windows Server 2008 R2

    Thursday, September 26, 2013 5:24 AM
  • Add smtp and make primary keeping existent proxy addresses

    ______________

    #CSV = alias,addnewemailaddress

    import-csv .\AddSmtpMakePrimaryProxy.csv | foreach {
    $user = Get-Mailbox $_.alias
    $user.emailAddresses+= $_.addnewemailaddress
    $user.primarysmtpaddress = $_.addnewemailaddress
    Set-Mailbox $user -emailAddresses $user.emailAddresses
    set-Mailbox $user -PrimarySmtpAddress $user.primarysmtpaddress
    }

    Friday, March 4, 2016 1:42 PM
  • #CSV = alias,addnewemailaddress

    import-csv .\AddSmtpMakePrimaryProxy.csv | foreach {
    $user = Get-Mailbox $_.alias
    $user.emailAddresses+= $_.addnewemailaddress
    $user.primarysmtpaddress = $_.addnewemailaddress
    Set-Mailbox $user -emailAddresses $user.emailAddresses
    set-Mailbox $user -PrimarySmtpAddress $user.primarysmtpaddress
    }


    [PS] C:\Scripts\Primary SMTP>.\AddSmtpMakePrimaryProxy.ps1

    The operation couldn't be performed because object 'XXX' couldn't be found on 'DC'.
        + CategoryInfo          : NotSpecified: (:) [Get-Mailbox], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : CE8CDFE8,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
        + PSComputerName        : DC

    . : Property 'emailAddresses' cannot be found on this object; make sure it exists and is settable.
    At C:\Scripts\Primary SMTP\AddSmtpMakePrimaryProxy.ps1:5 char:7
    + $user. <<<< emailAddresses+= $_.addnewemailaddress
        + CategoryInfo          : InvalidOperation: (emailAddresses:String) [], RuntimeException
        + FullyQualifiedErrorId : PropertyNotFound

    . : Property 'primarysmtpaddress' cannot be found on this object; make sure it exists and is settable.
    At C:\Scripts\Primary SMTP\AddSmtpMakePrimaryProxy.ps1:6 char:7
    + $user. <<<< primarysmtpaddress = $_.addnewemailaddress
        + CategoryInfo          : InvalidOperation: (primarysmtpaddress:String) [], RuntimeException
        + FullyQualifiedErrorId : PropertyNotFound

    Cannot bind argument to parameter 'Identity' because it is null.
        + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-Mailbox
        + PSComputerName        : DC

    Cannot process argument transformation on parameter 'PrimarySmtpAddress'. Cannot convert null to type "Microsoft.Exchan
    ge.Data.SmtpAddress".
        + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
        + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
        + PSComputerName        : DC

    Tuesday, October 25, 2016 7:12 PM