Error When running Script to Create Bulk AD Accounts

Hello Experts.

I have about 6500 user accounts I need to create in active directory and I was wondering if there was a quick way of doing this.   I got this script online, but I get an error message

Script: f:\prg\scriptsbatch\adtools\CreateBulk.vbs
Line: 19
Char: 1
Error: 0x80005000
Code:  80005000
Source: (null)

Here is my user file

sAMAccountName      CN      GivenName      SN      Password
autotest1      Auto1      Auto1 Test1      Test1      P@ssword
autotest2      Auto2      Auto2 Test2      Test2      P@ssword
autotest3      Auto3      Auto3 Test3      Test3      P@ssword
autotest4      Auto4      Auto4 Test4      Test4      P@ssword
autotest5      Auto5      Auto5 Test5      Test5      P@ssword
autotest6      Auto6      Auto6 Test6      Test6      P@ssword

' UserSpreadsheet .vbs
' Sample VBScript to create User accounts from a spreadsheet
' Author Guy Thomas
' Version 4.6 - June 2005
' ------------------------------------------------------' 
Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strPWD

' -------------------------------------------------------------'
' Important change OU= and strSheet to reflect your domain
' -------------------------------------------------------------'
strOU = "OU=GRPsers, dc=mytest, dc=local" ' Note the comma
strSheet = "F:\prg\ScriptsBatch\AD_Management\CreateBulkUserList.xls"
' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 2 'Row 1 often contains headings
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = ""
   strSam = Trim(objExcel.Cells(intRow, 1).Value)
   strCN = Trim(objExcel.Cells(intRow, 2).Value) 
   strFirst = Trim(objExcel.Cells(intRow, 3).Value)
   strLast = Trim(objExcel.Cells(intRow, 4).Value)
   strPWD = Trim(objExcel.Cells(intRow, 5).Value)
   ' Build the actual User from data in strSheet.
   Set objUser = objContainer.Create("User", "cn=" & strCN)
   objUser.sAMAccountName = strSam
   objUser.givenName = strFirst = strLast
   ' Separate section to enable account with its password
   objUser.userAccountControl = 512
   objUser.pwdLastSet = 0
   objUser.SetPassword strPWD
intRow = intRow + 1
' End of Sample UserSpreadsheet VBScript.

Open in new window

Who is Participating?
snoopscratchyConnect With a Mentor Commented:

The error 0x80005000 means "The specified directory service attribute or value does not exist" and I think that I have identified your problem :

The fact is that you use the full LDAP path in "strOU", so to match the path you set "strOU" to, you have to do the following :

Set objContainer = GetObject("LDAP://" & strOU & _

Open in new window

Set objContainer = GetObject("LDAP://" & strOU)

Open in new window

objRootLDAP.Get("defaultNamingContext") returns "dc=mytest, dc=local" so your LDAP path was looking like "OU=MyOU,dc=mytest,dc=local,dc=mytest,dc=local"

Hope this works now !


Maybe the problem comes from this line :

strOU = "OU=GRPsers, dc=mytest, dc=local" ' Note the comma

Open in new window

You need to set it to your current domain and probably that dc=mytest, dc=local does not match your current domain.

Can you try this and tell us if it helps ?

epicazoAuthor Commented:
I put that here only for MASKING purposes, but still didn't work.
epicazoAuthor Commented:
Thanks a million
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.