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 1:29pm
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 3:59pm
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 4:25pm
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 4:50pm
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 7:58pm
Thank you Ravish. This worked for me.
Free Windows Admin Tool Kit Click here and download it now
January 30th, 2011 8:18am
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
July 29th, 2011 1:32am
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.
Free Windows Admin Tool Kit Click here and download it now
January 28th, 2012 10:40am
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
January 28th, 2012 4:36pm
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}
}
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2012 6:53pm
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
}
April 28th, 2012 7:37pm