Rui J.M. Silva Blog RSS

All Blogs  »  Rui J.M. Silva Blog  »  EHLO  »  Blog article: Notes from the field - Part II: scripting

Notes from the field - Part II: scripting

During the migration project I was involved in, I did a lot of scripting. There are a lot of tasks that can only be done by extensive manual labor or by a script. I prefer this last option!

One of the tasks I had to do was to create a lot of mail-enabled contacts in the Active Directory. The script that does this reads the information needed from a text file and the creates the AD objects. The text file has the following format:

name;e-mail

And here’s the VBScipt that does all the work:

Option Explicit
Const ForReading = 1
Const ForWriting = 2

Dim objFSO, objFileIn, objOU, objUser
Dim MyArray, strName, strMail

On Error Resume Next
Set objFSO = CreateObject(”Scripting.FileSystemObject”)
Set objFileIn = objFSO.OpenTextFile(”INPUT_FILE.txt”, ForReading, True)

Set objOU = GetObject(”LDAP://ou=Contacts,dc=domain,dc=com“)

Do While Not objFileIn.AtEndofStream
MyArray = Split(objFileIn.ReadLine, “;”, -1, 1)
strName = MyArray(0))
strMail = MyArray(1)

Set objUser = objOU.Create(”contact”, strName)
objUser.Put “Description”, strName
objUser.Put “Mail”, strMail
objUser.SetInfo

Loop

objFileIn.Close
objFileOut.Close

Technorati : ,

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

If CAPTCHA image is missing or you cannot read the characters above, please generate a




Receive all the latest articles by email!

Receive Real-Time & Monthly MSExchange.org article updates in your mailbox. Enter your email below!
Click for Real-Time sample & Monthly sample

Become an MSExchange.org member!

Discuss your Exchange Server issues with thousands of other Exchange experts. Click here to join!

Solution Center