Adding multiple contacts from csv file and adding Secondary x500 email address same time
hi
i am trying to add multiple contacs from a csv file which also contain x500 addresses using powerhell, i can add the contacs with the email address but not the x500 same time.
the code i used to add multiple contacts is below. can you advice how to add the x500 at the same time please using a csv file. I am running exchange 2007 sp1 with rollup update 9.
code below works to add contacs without the x500 address.
Add-Content c:\debug.txt "::Starting Import: ";
$err = "";
Import-Csv Contacts.csv | ForEach-Object{
New-MailContact -DomainController dc01.fty.com -Name $_."displayName" -Firstname $_."FirstName" -Lastname $_."LastName" -ExternalEmailAddress $_."E-mail Address" -OrganizationalUnit "fty.com/tst" -ErrorAction SilentlyContinue -ErrorVariable +err | Set-Contact -DomainController dc01.fty.com -City $_."Business City" -Company $_."Company" -Office $_."Office" -DisplayName $_."displayName" -Fax $_."Business Fax" -Name $_."displayName" -Phone $_."Business Phone" -PostalCode $_."Business Postal Code" -StateOrProvince $_."Business State" -StreetAddress $_."Business Street" -Title $_."Title" -ErrorAction SilentlyContinue -ErrorVariable +err;
Set-MailContact -Identity $_."displayName" -DomainController dc01.fty.com -ErrorAction SilentlyContinue -ErrorVariable +err;}Add-Content c:\debug.txt $err;
March 21st, 2010 9:28pm
Hi Henock
An X500 address forms part of the proxyAddresses multi-valued attribute. Here's some sample powershell 1.0 code to modify a multi-valued attribute:
#constant
$ADS_PROPERTY_APPEND = 3
#variables
$attname = "proxyAddresses"
$attvalue = "X500:/O=fabrikam/OU=northamerica/cn=Recipients/cn=user1"
$ADObj = "CN=user1,dc=fabrikam,dc=com"
#working
$scp = [ADSI]"LDAP://$ADObj"
$scp.putEx($ADS_PROPERTY_APPEND,$attname,@("$attvalue"))
$scp.setInfo()
#finished
You could combine this with a script to import contacts such as the one shown here:
http://www.open-a-socket.com/index.php/2009/12/13/bulk-create-active-directory-contact-objects/
Tony
Free Windows Admin Tool Kit Click here and download it now
March 21st, 2010 11:57pm
thanks
March 23rd, 2010 7:24pm