Exchange 2007 Adding Target addresses Script

Hi Readers,

I am working on some merger project in which we have to add forwarding to different domain email addresses for other company users.

This is the first Phase of the Project.

Below is the Script that I have written to achieve this task :- (thanks to Quest Active Directory management Shell)

Create folders c:\script\mergerscript

Place the script & input file in this folder

Input file content example:-(csv file)

——————————————————————————————————-

userid,forwarding
Vikas.Sukhija@lab.com,emailaddress@yahoo.com

——————————————————————————————————-

################################################################################################
##           Script to add Target address (MergerScript)                                      ##
##           Author: Vikas Sukhija                                                  ##
##           Date: 07-10-2012                                        ##
##           Description:- This script is used for updating target address from Input file##
################################################################################################

# Import CSV file that is populated with user id (email address) & email address

$now=Get-Date -format “dd-MMM-yyyy HH:mm”

# replace : by –

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

$data = import-csv $args[0]

# Loop thru the data from CSV

foreach ($i in $data)

{

$userobject = get-qaduser $i.userid -IncludedProperties “TargetAddress”

$Target = $userobject.targetaddress

if ($Target -like $null)
{

# adding log to check current Target address is blank

$Log1 = “C:\scripts\MergerScript\BlankTarget” + $now + “.log”

Add-content  $Log1 “$userobject has blank Target address”

# If address is Blank then populate the address from the csv file

Get-QADUser $i.userid | Set-QADUser -ObjectAttributes @{targetAddress = $i.forwarding}

$userobject = get-qaduser $i.userid -IncludedProperties “TargetAddress”

$Target = $userobject.targetaddress

$Log3 = “C:\scripts\MergerScript\SetTarget” + $now + “.log”

Add-content  $Log3 “For $userobject $Target Target address has been set”

}

else

{

# adding log to check current Target address is not blank , then target address will not be updated.

$Log2 = “C:\scripts\MergerScript\CurrentTarget” + $now + “.log”
Add-content  $Log2 “$userobject already has $Target as Target address”

}
}
###############################################################################################################

Script usage :- Script.ps1 Csvfile

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