none
Powershell Add Secondary SMTP Address in bulk for Exchange Server 2010 SP1

    Question

  • Hello,

    Is it possible to add secondary smtp address in bulk through local EMS with Powershell in Exchange 2010 SP1 Mailboxes?

    This is how we used to import from CSV and add secondary smtp addresses in Exchange 2007 SP2.

    /***************

    Create the CSV file as Users.csv

    add1,add2
    address1@domain1.com,address2@domain2.com
    .....,......

    Created a Powershell script for following

    Import-CSV Users.csv | foreach {
    $Temp = Get-Mailbox -Identity $_.add1
    $Temp.EmailAddresses.Add($_.add2)
    Set-Mailbox -Instance $Temp }

    ***************/

    We are trying the following for Exchange 2010 SP1 and it DOES NOT seem to work.

    /***************

    Import-CSV Users.csv | foreach {
    $Temp = Get-Mailbox -Identity $_.add1
    $Temp.EmailAddresses += ("smtp:'$_.add2'")
    Set-Mailbox -Identity $_.add1 -EmailAddresses $Temp.EmailAddresses
     }

    ***************/

     

    The error is as follows...

     

    Exception setting "EmailAddresses": "Cannot convert value "System.Object[]" to type "Microsoft.Exchange.Data.ProxyAddressCollection". Error: "The address 'smtp:'@{add1=address1@domain1.com; add2=add2@domain2.com'' is invalid: The address ''@{add1=address1@domain1.com; add2=add2@domain2.com}.add2'' is not a valid SMTP address.""
    At C:\1.ps1:4 char:7 + $Temp. <<<< EmailAddresses += ("smtp:'$_.add2'")    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : PropertyAssignmentException

     

    Appreciate your assistance.

    Exchange 2010 SP1 / Powershell 2.0

    Thursday, January 27, 2011 1:27 PM

Answers

  • This works for me

    Import-CSV Users.csv | foreach {
    $Temp = (Get-Mailbox -Identity $_.add1).emailaddresses
    $Temp += $_.add2
    Set-Mailbox -identity $_.add1 -emailaddresses $Temp }
    Friday, January 28, 2011 6:40 AM

All replies

  • This works for me

    Import-CSV Users.csv | foreach {
    $Temp = (Get-Mailbox -Identity $_.add1).emailaddresses
    $Temp += $_.add2
    Set-Mailbox -identity $_.add1 -emailaddresses $Temp }
    Friday, January 28, 2011 6:40 AM
  • Thank you Vojin. This works for me as well.
    Sunday, January 30, 2011 5:16 AM