Add non-exchange email address to existing users in Active Directory

Hi.  I need to add a gmail address to some of my existing AD users.  I think it can be done using the Set-ADUser -Add command in powershell but i can't figure out the rest of the commands.  Ideally i would want the Set-ADUser command to cross reference a csv file with all of the usernames and email addresses listed.  If anyone can help that's be great, Please don't forget the layout for the csv file.  Thanks.

Who is Participating?
FOXConnect With a Mentor Active Directory/Exchange EngineerCommented:
2 columns- at the top of your adusers column name it users, the other column with the email address just name it address

Save the file as emailaddresses.csv

$Users=Import-csv "c:\filelocation\emailaddresses.csv" | foreach{Get-Aduser $_.users | Set-Aduser -emailaddress $_.address}
Michael NietoFounderCommented:
Try this powershell script:
Add-Content c:\debug.txt "::Starting Import: "; 

$err = ""; 

Import-Csv contacts.csv | ForEach-Object{ 

$contact = Get-MailContact $_."displayname" -DomainController YOURDOMAIN.COM 
$contact.EmailAddresses += $_."ex" 
$contact | Set-MailContact 
Add-Content c:\debug.txt $err;

Open in new window

tech218Author Commented:
I really do appreciate your time but that is very confusing to me...

I need to update users based on username (sAMAccountName?) not displayname (am i reading that right?)
What is the debug.txt file?  Does it act as an error log?  Does it log what user accounts were changed\failed?
What information is in the .csv file?  Is it "sAMAccountName" plus ""?  What are the headers or does it need headers?

Does this make sense?  Thanks.

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

tech218Author Commented:
FoxLUV, thanks for the post.  I have a question.  Is this what you meant for the column headings?


Please correct if wrong.  Thanks.

tech218Author Commented:
Foxluv, I figured it out based on common sense and a successful test...When i do this en masse, i will let you know the results.  Thanks.

tech218Author Commented:
Worked like a champ!  Over 5500 users now have an email address associated with their logon.  Thanks.
FOXActive Directory/Exchange EngineerCommented:
Nice work!!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.