locked
how to import multiple SMTP addresses using Exchange 2007 SP3 powershel; RRS feed

  • Question

  • Hello there I copied Ravish's scripts to a notepad and save it as import.ps1.

    Import-Csv IDs.csv | Foreach-Object{
       $user = Get-Mailbox -Identity $_.Alias
       $user.EmailAddresses+=$_.SecondaryAddress
       Set-Mailbox $user -EmailAddresses $user.EmailAddresses  
    }

    Here is my Csv file format:

    Alias  SecondaryAddress
    user1 SMTP:user1@domain1.com;smtp:user1@domain2.com;smtp:user1.domain2.com

    user2 SMTP:user2@domain1.com;smtp:user2@domain2.com:smtp:user2@domain3.com

    and get the following errors that the SMTP address entry is invalid. How can I put multiple SMTP address in SecondaryAddress field

     

    Thanks a lot.

     

    Thursday, July 28, 2011 10:36 PM

Answers

  • That's telling us that $_.SecondaryAddress is null.

    It doesn't seem to like that .csv file. Are you sure those column headings are right, and there's no leading or trailing spaces in them?


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Marked as answer by exadmin818 Thursday, July 28, 2011 11:50 PM
    Thursday, July 28, 2011 11:45 PM

All replies

    1. Have you tried to create a EAP and used a filter?
    2. Have you create an accepted domain for the other domains?

    Sukh
    Thursday, July 28, 2011 10:46 PM
  • Not tested:

    Import-Csv IDs.csv | Foreach-Object{
       $user = Get-Mailbox -Identity $_.Alias
       $user.EmailAddresses+=($_.SecondaryAddress -split ";")
       Set-Mailbox $user -EmailAddresses $user.EmailAddresses
    }

    That should give you an array of address from the semi-colon delimited list.  It may not like having that first one there with the SMTP (caps) prefix.  That denotes the primary SMTP address, and there's already going to be one in the user email addresses.


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, July 28, 2011 10:56 PM
  • here is the easier way to do it. just break up the muti-value attribute.

    ----------------------------

    Get-Mailbox -resultsize 9999| Select Name, @{Name=’EmailAddresses’;Expression={[string]::join(",", ($_.EmailAddresses))}} | Export-CSV c:\EmailAddress.csv


    got a question? guarantee answers at: http://www.infotechguyz.com/forum/
    • Proposed as answer by Denny415 Thursday, July 28, 2011 11:18 PM
    Thursday, July 28, 2011 11:17 PM
  • Thanks for quick reply...

     

    I get the following error:

    You must provide a value expression on the right-hand side of the '-' operator.
    At D:\Program Files\Microsoft\Exchange Server\Scripts\import.ps1:3 char:48
    +    $user.EmailAddresses+=($_.SecondaryAddress -s <<<< plit ";")
    [PS] C:\scripts>

    Thursday, July 28, 2011 11:21 PM
  • Let's try a different tack:

    Import-Csv IDs.csv | Foreach-Object{
       $user = Get-Mailbox -Identity $_.Alias
       $user.EmailAddresses += (($_.SecondaryAddress).split(";"))
       Set-Mailbox $user -EmailAddresses $user.EmailAddresses
    }

     


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, July 28, 2011 11:26 PM
  • here is the error:

     

    [PS] C:\scripts>import.ps1
    You cannot call a method on a null-valued expression.
    At D:\Program Files\Microsoft\Exchange Server\Scripts\import.ps1:3 char:56
    +    $user.EmailAddresses += (($_.SecondaryAddress).split( <<<< ";"))
    You cannot call a method on a null-valued expression.
    At D:\Program Files\Microsoft\Exchange Server\Scripts\import.ps1:3 char:56
    +    $user.EmailAddresses += (($_.SecondaryAddress).split( <<<< ";"))

    Thursday, July 28, 2011 11:31 PM
  • That's telling us that $_.SecondaryAddress is null.

    It doesn't seem to like that .csv file. Are you sure those column headings are right, and there's no leading or trailing spaces in them?


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Marked as answer by exadmin818 Thursday, July 28, 2011 11:50 PM
    Thursday, July 28, 2011 11:45 PM
  • sorry. My mistake. the script works great. Thanks all for your input and help. BTW, SMTP entry works fine since I uncheck EAP option.
    Thursday, July 28, 2011 11:52 PM
  • No problem.  Glad you got it to work :).
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, July 28, 2011 11:54 PM