Adding secondary email address

Hi Readers,

Just want to share the the script to add secondary email address from CSV file.

CSV file format is as below:-

userid,forwarding
Vikas.Sukhija@xxxxxxxxxxxxx.com,sukhijv@yyyyyyyy.com

Log Path :- C:\scripts\MergerScript

We have used it in merging the another organization that Our Company aquired.

Dont get confuse with the word forwarding Its secondary email address, I just used as We were writing lot of scripts when we acquired one more company.

######################################################################
#             Author: Vikas Sukhija
#             Date: 02/27/2013
#             Description: Adding secondary email address
#####################################################################

#—-ADD Exchange Shell——-

If ((Get-PSSnapin | where {$_.Name -match “Exchange.Management”}) -eq $null)
{
 Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
}
$now=Get-Date -format “dd-MMM-yyyy HH:mm”

# replace : by –

$now = $now.ToString().Replace(“:”, “-”)

$Log1 = “C:\scripts\MergerScript\AddSecondAddress” + $now + “.log”
#—–Import CSV

$data = import-csv $args[0]

if ($? -like “False”)

{

exit

}

# loop thru the malboxes now

foreach ($i in $data)

{
$secondaryemail = $i.forwarding

$mailbox = get-mailbox $i.userid

# check for error

if ($? -like “False”)

{

exit

}
Write-host “$secondaryemail email address will be added to $mailbox”
#get in to multivalued attribute & add one more value

$mailbox.emailaddresses+= $secondaryemail

$mailbox | set-mailbox

Add-content  $Log1 “$secondaryemail email address added to $mailbox”

}

############################################################################

Regards

Sukhija Vikas

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s