Solved

Active Diretory Add User VB Script Question

Posted on 2010-09-02
5
790 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
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 38

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now