?
Solved

Active Diretory Add User VB Script Question

Posted on 2010-09-02
5
Medium Priority
?
798 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 668 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 42

Assisted Solution

by:Adam Brown
Adam Brown earned 668 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 664 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 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