• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 800
  • Last Modified:

Active Diretory Add User VB Script Question

Hello I wrote a script to add new users to Active Directory based on an input from an excel sheet. I am confused on the error I am getting. The script makes it to the second iteration of int row (i added in the wscript.echo(introw) for debugging purposes) then gives an Object already exists error on line 21. Which is the first objuser.setinfo.

The first user in the excel sheet is created in active directory but no more. I cant figure out why Im getting the object already exists error as the introw does increment successfully, so all the data should be different?

Paul.
Untitled.jpg
0
el_marquez
Asked:
el_marquez
3 Solutions
 
tonyszkoCommented:
Please post also a script source - probably there is some mistake in variables initialization and incrementing values.
0
 
dax_badCommented:
Hey mate,
The common name (CN) needs to be unique as well. Try different names for second and third entry in the spreadsheet.

/Daniel
0
 
Adam BrownSr Solutions ArchitectCommented:
Honestly, if you're using Windows 2008 (I assume you are, since you're posting in the Windows 2008 zone), I'd highly recommend getting into Powershell for this type of thing. The script to do what you want is about two lines with Powershell. This will give you a little more information on what you need to do: http://www.experts-exchange.com/Software/Server_Software/File_Servers/Active_Directory/Q_26333527.html
The trick is building a csv file that has the data you want and piping the import-csv cmdlet to the new-aduser cmdlet. Let me know if you can't get something that works out of the link there and I'll see if I can put together a custom one for you.

0
 
el_marquezAuthor Commented:
Ill look into the powershell, I apologize I completely forgot to post the script. Here it is:

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    ("C:\exceladscript\testusers.xlsx")

Set objOU = GetObject("LDAP://OU=Testusers,OU=Architecture,DC=arch,DC=ryerson,DC=ca")


intRow = 2
Do Until objExcel.Cells(intRow,1).Value = "1"


wscript.echo(introw)
Set objUser = objOU.Create("User", "cn=" & objExcel.Cells(intRow, 1).Value)
objUser.Put "sAMAccountName", objExcel.Cells(intRow, 2).Value
objUser.Put "name", objExcel.Cells(intRow, 3).Value
objUser.Put "displayName", objExcel.Cells(intRow, 4).Value

objUser.Put "homeDirectory", objExcel.Cells(intRow, 5).Value


objUser.SetInfo
objUser.Put "homeDrive", "H"
objUser.Put "description", "1st Year Architecture Student"
objUser.SetPassword objExcel.Cells(intRow, 6).Value
objUser.Put "pwdLastSet", 0
objUser.AccountDisabled = FALSE
objUser.AccountExpirationDate = "09/01/2014"


objUser.SetInfo

    intRow = intRow + 1
Loop
objExcel.Quit
0
 
tonyszkoCommented:
dax_bad gave you good advice - this is a problem with CN being not unique. CN is RDN of an object and it has to be unique if objects are in the same container.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now