none
script to add another email address for the existing users RRS feed

  • Question

  • Hello,

    I am looking for a Power Shell script to add new SMTP address 200 users and do not want to touch existing SMTP and X.500 addresses. am using Exchange server 2010 sp1

    Can someone help ?

    i tried with the below script executing on exchange PS, i didnt receive any error and there is no result also.. 

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


    srini

    Thursday, September 26, 2013 3:53 AM

Answers

  • Hi,

    Use this script :

    Import-Csv c:\data.csv | Foreach{set-mailbox -identity $_.Alias -EmailAddresses @{add=$_.emailaddress}}

     Make sure  you have  a data.csv file with  at least two header  like below :

    Alias,emailaddress

    user1,user1@newaddress.com

    .............


    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

    • Marked as answer by k srinivas Thursday, September 26, 2013 6:08 AM
    Thursday, September 26, 2013 4:33 AM

All replies

  • Hi,

    Use this script :

    Import-Csv c:\data.csv | Foreach{set-mailbox -identity $_.Alias -EmailAddresses @{add=$_.emailaddress}}

     Make sure  you have  a data.csv file with  at least two header  like below :

    Alias,emailaddress

    user1,user1@newaddress.com

    .............


    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

    • Marked as answer by k srinivas Thursday, September 26, 2013 6:08 AM
    Thursday, September 26, 2013 4:33 AM
  • Dear Noorain, 

    thank you so much. its worked perfectly...

    have a nice day :)


    srini

    Thursday, September 26, 2013 6:08 AM
  • Thank you very much Noorain.
    Monday, January 13, 2014 3:33 PM
  • Hi Noorain,

    I have to add 7 secondary addresses and need to change primary address for existing users. I tried the above command to add secondary addresses and received the below error

    Import-Csv : The member "emailaddress" is already present.

    Appreciate your valuable efforts.


    Nandha

    Monday, January 11, 2016 3:33 PM
  • Add smtp and make primary, add proxy addresses, keep existent proxy addresses

    ______________

    #CSV = alias,addnewemailaddress,proxy1

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

    ____________________________________________

    #CSV = alias,addnewemailaddress,proxy1,proxy2

    import-csv .\AddSmtpMakePrimaryProxyPlus.csv | foreach {
    $user = Get-Mailbox $_.alias
    $user.emailAddresses+= $_.addnewemailaddress
    $user.primarysmtpaddress = $_.addnewemailaddress
    $proxy1 = $_.proxy1
    $proxy2 = $_.proxy2
    Set-Mailbox $user -emailAddresses $user.emailAddresses
    set-Mailbox $user -PrimarySmtpAddress $user.primarysmtpaddress
    Set-Mailbox $user -EmailAddresses @{add= $proxy1,$proxy2}
    }

    Friday, March 4, 2016 1:39 PM
  • I need to Add smtp and make it primary annd keep existent proxy addresses.

    Tuesday, October 25, 2016 7:04 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:13 PM