Solved

Active Diretory Add User VB Script Question

Posted on 2010-09-02
5
796 Views
Last Modified: 2012-06-27
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
Comment
Question by:el_marquez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:tonyszko
ID: 33591464
Please post also a script source - probably there is some mistake in variables initialization and incrementing values.
0
 
LVL 6

Accepted Solution

by:
dax_bad earned 167 total points
ID: 33591479
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
 
LVL 40

Assisted Solution

by:Adam Brown
Adam Brown earned 167 total points
ID: 33592716
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
 

Author Comment

by:el_marquez
ID: 33596469
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
 
LVL 3

Assisted Solution

by:tonyszko
tonyszko earned 166 total points
ID: 33596690
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to install and use the NTBackup utility that comes with Windows Server.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

730 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