Submitted By: ASIF M

Uses information stored in a Microsoft Excel spreadsheet to create a series of Active Directory computer accounts.

Visual Basic
Edit|Remove
Option Explicit
Dim strComputer, strOU, strSheet, intRow
Dim objRootLDAP, objContainer, objComputer, objShell
Dim objExcel, objSpread 

' -------------------------------------------------------------'
' Important change OU= and strSheet to reflect your domain
' -------------------------------------------------------------'

strOU = "OU=Accounts7 ," ' Note the comma
strSheet = "E:\scripts\Computers1.xls" 

' Bind to Active Directory, Computers container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext")) 

' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 2 'Row 1 often containes headings

' Here is the loop that cycles through the cells
Do Until objExcel.Cells(intRow,1).Value = ""
   strComputer = objExcel.Cells(intRow, 1).Value

   ' Build the actual computer.
   Set objComputer = objContainer.Create("Computer", _
   "cn=" &   strComputer)
   objComputer.Put "sAMAccountName", strComputer & "$"
   objComputer.Put "userAccountControl", 4096
   objComputer.SetInfo 
   intRow = intRow + 1
Loop
objExcel.Quit 

WScript.Quit