Import Email addresses from CSV file into Active Directory Windows 2003


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,

Bjarte FjellandAsked:
Who is Participating?
Chris DentConnect With a Mentor PowerShell DeveloperCommented:

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

Chris DentPowerShell DeveloperCommented:


With Exchange or without?

Bjarte FjellandAuthor Commented:
Hi Chris,

It's without Exchange, we are using Lotus Notes.
Bjarte FjellandAuthor Commented:
Thank you, that worked perfectly!
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.