Solved

Active Diretory Add User VB Script Question

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

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

746 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

13 Experts available now in Live!

Get 1:1 Help Now