locked
Powershell Add Secondary SMTP Address in bulk for Exchange Server 2010 SP1 RRS feed

  • 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 10:29 AM

Answers

  • Hi,

    Assming the csv file has at list this header columns: LoginName and SecondayAddress

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


    Ravi | MCSE Messaging - 2003. This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, January 27, 2011 1:50 PM

All replies

  • You can try this:

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


    With kind regards
    Krystian Zieja
    http://www.projectnenvision.com
    Follow me on twitter
    My Blog
    Thursday, January 27, 2011 12:59 PM
  • Thanks Krystian.

    That returns the following error in Exchange 2010 SP1.

    A positional parameter cannot be found that accepts argument 'User Name'.
        + CategoryInfo          : InvalidArgument: (:) [Set-Mailbox], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Set-Mailbox

    However, it works fine in Exchange 2007 SP2.

    Thursday, January 27, 2011 1:25 PM
  • Hi,

    Assming the csv file has at list this header columns: LoginName and SecondayAddress

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


    Ravi | MCSE Messaging - 2003. This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, January 27, 2011 1:50 PM
  • Hi, Please update on the above script, is this worked for you?
    Ravi | MCSE Messaging - 2003. This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, January 28, 2011 4:58 PM
  • Thank you Ravish. This worked for me.
    Sunday, January 30, 2011 5:18 AM
  • Hi Ravish,

    I copied your 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

     

    Thursday, July 28, 2011 10:32 PM
  • I am attempting to add a secondary SMTP address without touching the primary.

    I am running the following script but keep receiving a warning. I'm not sure if its actually trying to change the primary as well or not. Please help 

    Import-Csv c:\temp\test.csv | Foreach-Object{
       $user = Get-Mailbox -Identity $_.LoginName
       $user.EmailAddresses+=$_.Secondsmtp
       Set-Mailbox $user -EmailAddresses $user.EmailAddresses
    }

     

    CSV File named test.csv

    headers: loginname, secondsmtp

     

    Heres the warning i keep getting

    [PS] C:\Windows\system32>c:\temp\test.ps1
    WARNING: Couldn't update the primary SMTP address because this mailbox is configured to use an e-mail address policy.
    To disable the e-mail address policy for this mailbox, run the command with the EmailAddressPolicyEnabled parameter set
     to $false.

     

    Now this script will be making the change on about 200 users and I dont want to go go through every account to make sure this policy is enabled, just want to make sure nothing goes wrong when i execute the full csv file.

     

     

     

    Thursday, January 26, 2012 3:38 PM
  • Sean,

    The CMD for to uncheck the 'emailaddresspolicy' is Set-mailbox -EmailAddressPolicyEnabled $false

    You should be able to just add another line in the 'ForEach' before you add the add'l addy.

    perhaps something like:

    Import-Csv c:\temp\test.csv | Foreach-Object{

       $user = Get-Mailbox -Identity $_.LoginName
       $user.EmailAddresses+=$_.Secondsmtp
    Set-mailbox -EmailAddressPolicyEnabled $false 
    Set-Mailbox $user -EmailAddresses $user.EmailAddresses

    }

    Also, if you don't want to integrate it into the rest of the script, just use a list of the logons/aliases in a single column, and then run get-content filename.txt | Set-mailbox -EmailAddressPolicyEnabled $false 

    All 200 of your users are taken care of at once and then you can move on to reset the email addy's.

     Hope this helps.

     


    "If You're Gonna Shoot, Shoot. Don't Talk." - Tuco
    • Edited by El-Kabong Friday, January 27, 2012 9:56 PM
    • Proposed as answer by Prabhat Nigam Thursday, March 8, 2012 11:42 PM
    • Unproposed as answer by Prabhat Nigam Thursday, March 8, 2012 11:42 PM
    Friday, January 27, 2012 9:30 PM
  • This article works good with exchange 2010 so I am write some changes http://msexchangeguru.com/2011/06/09/e2k7addremove-email-id-for-bulk-users/ so meanwhile I have test this one below which is working for me.

    Import-csv c:\temp\data.csv | ForEach-Object{
    $maileg = $_.Name
    $ProxyAdd = $_.proxyaddresses -split ';'
    Set-mailuser -identity $maileg -EmailAddressPolicyEnabled $false  -Emailaddresses @{add= $proxyAdd}
    }

    Thursday, March 8, 2012 11:48 PM
  • Ok this is working for me. I am doing this on mailuser if you need to use the same for mailbox then remember to change set-mailbox

    Import-Csv c:\temp\data.csv | Foreach{
    $maileg = Get-Mailuser -Identity $_.Name
    $maileg.EmailAddresses += $_.email -split ';'
    $maileg | Set-Mailuser -EmailAddresses $maileg.EmailAddresses   
    }

    Friday, March 9, 2012 12:32 AM
  • Hi All,

    We can do it easily by CSV and Powershell..

    Import-Csv "D:\emailset.csv" |ForEach{Set-Mailbox -identity $_.userprincipalname -EmailAddresses $_.Primaryemailaddress,$_.SecondaryemailAddress,$_.thirdemailaddress}


    Kirpal Singh

    Thursday, July 3, 2014 1:28 PM
  • Mr. Kirpal Singh thanks a lot it helped me to add additional email addresses for 800 mailboxes quickly.

    Lloyd

    • Proposed as answer by Lloyd01 Tuesday, September 9, 2014 8:35 AM
    Tuesday, September 9, 2014 8:34 AM
  • Hi Kirpal,

    I'm new to Poweshell and I saw your script which I believe will help me. I have a large number of clients to add additional smtp addresses to, but not to the whole organization.

    I just have one question. If for example to test the script, I only had 2 names in the .csv file. Would it only change the 2 names? I know this sounds like a dumb question, but I'm just a little paranoid about affecting all other exchange clients. Wiping out information for names that don't exist in the .csv file.

    Tuesday, November 11, 2014 8:51 PM
  • Hi Roberta,

    You need to define only those users in CSV, on which you want to set SMTP Address.

    Thanks


    Kirpal Singh

    Saturday, February 27, 2016 5:38 AM