Powershell Add Secondary SMTP Address in bulk for Exchange Server 2010 SP1
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
January 27th, 2011 5:36am
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
Free Windows Admin Tool Kit Click here and download it now
January 27th, 2011 8:00am
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.
January 27th, 2011 8:27am
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.
Free Windows Admin Tool Kit Click here and download it now
January 27th, 2011 8:50am
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.
January 28th, 2011 12:00pm
Thank you Ravish. This worked for me.
Free Windows Admin Tool Kit Click here and download it now
January 30th, 2011 12:22am