Import Email addresses from CSV file into Active Directory Windows 2003

Posted on 2009-02-11
Medium Priority
Last Modified: 2012-05-06

I have a CSV file that containing Last Name, First Name , User Name , Email data.
Last Name, First Name and User Name are already in the AD and in use, but i need to add the Email part without generating more User accout problem :o(

Any script or command syntax that I can use?

Best regards,

Question by:Bjarte Fjelland
  • 2
  • 2
LVL 71

Expert Comment

by:Chris Dent
ID: 23611524


With Exchange or without?


Author Comment

by:Bjarte Fjelland
ID: 23611595
Hi Chris,

It's without Exchange, we are using Lotus Notes.
LVL 71

Accepted Solution

Chris Dent earned 2000 total points
ID: 23611830

Great, just didn't want to break that :)

The following VbScript (save as .vbs) takes a simple CSV file in the following format:


And imports the Email into the mail field (as seen on the general tab in AD Users and Computers) for each Username.

I recommend you test it on a very small set of users before feeding it the entire CSV. Do let me know if the CSV file also includes quotes, that'll take a little more effort.

Option Explicit
Const FILE_NAME = "TheFile.csv"
Function GetObjectDN(strObject, strDomain)
  ' Return Type: String
  ' Returns a Distinguished Name for an Object from it's NT SAM ID.
  ' This will only function for valid object types within an NT Domain structure.
  Const ADS_NAME_TYPE_1779 = 1
  Const ADS_NAME_TYPE_NT4 = 3
  Dim objNameTranslate
  Dim strObjectDN
  On Error Resume Next : Err.Clear
  Set objNameTranslate = CreateObject("NameTranslate")
  objNameTranslate.Init ADS_NAME_INITTYPE_GC, ""
  objNameTranslate.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strObject
  strObjectDN = objNameTranslate.Get(ADS_NAME_TYPE_1779)
  If Err.Number <> 0 Then  ' Make the DN Blank for a Failed Search
    strObjectDN = ""
  End If
  Set objNameTranslate = Nothing
  On Error Goto 0
  GetObjectDN = strObjectDN
End Function
Dim objFileSystem : Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFileSystem.OpenTextFile(FILE_NAME, 1, False, 0)
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
Dim strDomain : strDomain = objNetwork.UserDomain
Do Until objFile.AtEndOfStream
  Dim arrLine : arrLine = Split(objFile.ReadLine, ",")
  Dim strUsername : strUsername = arrLine(2)
  Dim strEmail : strEmail = arrLine(3)
  Dim strDN : strDN = GetObjectDN(strUsername, strDomain)
  If strDN <> "" Then
    Dim objUser : Set objUser = GetObject("LDAP://" & strDN)
    objUser.Put "mail", strEmail
    Set objUser = Nothing
  End If

Open in new window


Author Closing Comment

by:Bjarte Fjelland
ID: 31545544
Thank you, that worked perfectly!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question