Solved

Error When running Script to Create Bulk AD Accounts

Posted on 2012-03-22
4
371 Views
Last Modified: 2012-03-26
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

CreateBulkUserList.xls
====================
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 http://computerperformance.co.uk/
' 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 & _
objRootLDAP.Get("defaultNamingContext")) 
' 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
   objUser.sn = strLast
   objUser.SetInfo
   ' Separate section to enable account with its password
   objUser.userAccountControl = 512
   objUser.pwdLastSet = 0
   objUser.SetPassword strPWD
   objUser.SetInfo
intRow = intRow + 1
Loop
objExcel.Quit 
WScript.Quit 
' End of Sample UserSpreadsheet VBScript.

Open in new window

0
Comment
Question by:epicazo
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:snoopscratchy
ID: 37752805
Hello,

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 ?

Yoann
0
 

Author Comment

by:epicazo
ID: 37753398
I put that here only for MASKING purposes, but still didn't work.
0
 
LVL 1

Accepted Solution

by:
snoopscratchy earned 500 total points
ID: 37753573
Right,

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 :

Change
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext"))

Open in new window

To
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 !

Yoann
0
 

Author Closing Comment

by:epicazo
ID: 37767458
Thanks a million
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question