CSV import to Global Address List

Hi Experts,

I am trying to import user data from a CSV file into our GAL.

Here's my command
 Import-Csv "C:\Temp\Contacts.csv" | ForEach-Object { New-MailContact -Name $_.Name -ExternalEmailAddress $_.Email-Address -FirstName $_.FirstName -LastName $_.LastName -OrganizationalUnit "ad.co.uk\ou_H‌‌ierarchicalAddressBook" -Alias $_.Name }

Open in new window


I've also attached an example of the CSV I've been using.

below is the error I am getting, any help would be greatly appreciated

ErrorContact.csv
LVL 1
Elliott ClarkDBAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael B. SmithExchange & Active Directory ExpertCommented:
Get rid of the "-" in Email-Address. If a CSV header isn't just alphanumeric, it needs to be quoted. And that leads to all sorts of complications.

Also, in your demo Contact.csv you spelled Firstname incorrectly.
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
The problem is the Dash in "Email-Address" property.
To solve this you should use single '

like this:
 Import-Csv .\Contact.csv | ForEach-Object { 
    New-MailContact -Name $_.Name -ExternalEmailAddress $_.'Email-address' -FirstName $_.FirstName -LastName $_.LastName -OrganizationalUnit "ad.co.uk\ou_H‌‌ierarchicalAddressBook" -Alias $_.Name 
}

Open in new window

0
FOXActive Directory/Exchange EngineerCommented:
Elliot - if your header reads Email-address then using the quotes as Jose has stated will correct your issue.

Send a screenshot of the headers on your .csv file so we can see what your issue is.  Or just change your header to emailaddress and in your script let it read  -ExternalEmailAddress  $_.emailaddress
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
FOX the CSV file is attached on the question .
0
Michael B. SmithExchange & Active Directory ExpertCommented:
We've all given the same answer in different ways. Let the poor OP respond. :-)
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
We should be glad he can pick one of all :) at least he has options haha
0
Elliott ClarkDBAAuthor Commented:
Hi All,

thank you for the overwhelming response!

Silly mistake by me I have taken the hyphen out however i'm getting a weirder error and I'm not sure if its the user data I have so here's another screenshot

I'm wondering if this is because there is a space in the full name?
If so this causes me quite a few issues as I have 10,000 records!

thanks for your help so far :)
Capture.PNG
0
FOXActive Directory/Exchange EngineerCommented:
Elliot,
Test the below on one contact- we can't have spaces in aliases so let's do FirstName_LastName to create the alias

Import-Csv "C:\Temp\Contacts.csv" | ForEach-Object { New-MailContact -Name $_.Name -ExternalEmailAddress $_.EmailAddress -FirstName $_.FirstName -LastName $_.LastName -OrganizationalUnit "ad.co.uk\ou_H‌‌ierarchicalAddressBook" -Alias  (($_.FirstName) + "_" + ($_.LastName))}
0
Elliott ClarkDBAAuthor Commented:
thanks guys!

last thing,  any idea how I can add attributes like department, job title and company?

thanks
0
FOXActive Directory/Exchange EngineerCommented:
Elliot to add the department, job title and company add those fields to your .csv and then we would have to combine the other command with the first one or run it seperately.  The below is combined in one script.  Being that you said you have 10000 records we will pause it for about 8 minutes to give it time to create all the contacts before we set the other attributes

Import-Csv "C:\Temp\Contacts.csv" | ForEach-Object { New-MailContact -Name $_.Name -ExternalEmailAddress $_.EmailAddress -FirstName $_.FirstName -LastName $_.LastName -OrganizationalUnit "ad.co.uk\ou_H‌‌ierarchicalAddressBook" -Alias  (($_.FirstName) + "_" + ($_.LastName))}
start-sleep -s 480
import-csv "C:\Temp\Contacts.csv"  | foreach-Object {Set-contact -identity $_.emailaddress  -Company $_.Company -Department $_.Department  -Title $_.Title}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Elliott ClarkDBAAuthor Commented:
thank you to everyone who assisted me with this
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.