NOTE: I just copied my code over. I have not edited the script to be more "global" and it still references absolute paths which I use for testing/logging - so you will need to modify the scripts some. I love helping - but need to leave a little bit of fun for you :D
here is a quick bit of code i have used:
<div>$email_temp_holder = get-mailbox $email
$email_temp_holder.emailaddresses += $new_email
set-mailbox $email -emailAddresses $email_temp_holder.emailaddresses</div><div>
The full code I use looks like this (this assumes I know the current email addresses)
#empties resulting log/text file
"">c:\Powershell\Paul_Test\results_file.txt
cls
#imports the text file containing the existing email addresses, one per line - its a text file but treated as a csv file. only one column with a heading of email
$list = Import-Csv "c:\Powershell\Paul_Test\concur_import.txt"
foreach($item in $list)
{
$email = $item.email
#gets the linked master account to generate the appropriate username of the personal smtp address
$user = (Get-Mailbox $email | select linkedmasteraccount).linkedmasteraccount
#determines if a linked master is found or not
if((Get-Mailbox $email | select linkedmasteraccount).linkedmasteraccount)
{
#generate the new prefix - before the @
$new_pre = (((get-qaduser $user -service vcpidc01.vcpi.com | select firstname).firstname).substring(0,1)) + ((Get-QADUser $user -Service vcpidc01.vcpi.com | select lastname).lastname)
Disconnect-QADService
$user_temp = (Get-Mailbox $email | select samaccountname).samaccountname
$user_info = ((Get-QADUser $user_temp | select UserPrincipalName).userprincipalname.split("@"))[1]
$new_email = $new_pre+"@"+$user_info
Write-Host $new_email
$flag = 0
$suffix = 0
do{
#we need to check if the email acocunt we want to create exists or not first before continuing
if(Get-Mailbox $new_email|select name)
{
Write-Host "Email found"
$suffix +=1
$new_email = $new_pre+$suffix+"@"+$user_info
Write-Host $suffix
}
else
{
$flag = 1
Write-Host "Email not found - setting the account up"
$email_temp_holder = get-mailbox $email
if($suffix -eq 0)
{
$new_email = $new_pre+"@"+$user_info
}
else
{
$new_email = $new_pre+$suffix+"@"+$user_info
}
#we turn off the emailadddresspolicy for other reasons
get-mailbox $email | set-mailbox -EmailAddressPolicyEnabled $false
$email_addresses = get-mailbox $email | select -expand EmailAddresses | %{$_.SmtpAddress}
$email_temp_holder.emailaddresses += $new_email
set-mailbox $email -emailAddresses $email_temp_holder.emailaddresses
$new_email >> c:\Powershell\Paul_Test\results_file.txt
}
}while($flag -eq 0)
}
}
For something like what you want to do (adding existing email addresses to the smtp address) I would modify my code as follows:
"">c:\Powershell\Paul_Test\results_file.txt
cls
$list = Import-Csv "c:\Powershell\Paul_Test\concur_import_2.csv"
foreach($item in $list)
{
$email = ""
$new_smtp = ""
$email_temp_holder = ""
$email = $item.email
$new_smtp = $item.new_smtp.split(";")
$email_temp_holder = get-mailbox $email
foreach($item_2 in $new_smtp)
{
$email_temp_holder.emailaddresses += $item_2
}
#get-mailbox $email | set-mailbox -EmailAddressPolicyEnabled $false
set-mailbox $email -emailAddresses $email_temp_holder.emailaddresses
}
You can of course add output to the screen/file as needed - but this will add those secondary smtp addresses for you. The csv file would be setup with the columns of: email and new_smtp. The column new_smtp can contain multiple email addresses separated by a ; so for the above snippet I used the below csv file to test my code out:
email,new_smtp
pdearment@test.com,pdtest@test.com;pdtest_2@test.com;pdtest3@testcorp.com