Import Email addresses from CSV file into Active Directory Windows 2003

Hi,

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
LVL 1
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:

FirstName,LastName,Username,Email

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.

Chris
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_INITTYPE_GC = 3
  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
    objUser.SetInfo
 
    Set objUser = Nothing
  End If
Loop

Open in new window

0
 
Chris DentPowerShell DeveloperCommented:

Hey,

With Exchange or without?

Chris
0
 
Bjarte FjellandAuthor Commented:
Hi Chris,

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