Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create multiple user accounts at 1 time 4

Status
Not open for further replies.

zacca

Technical User
Dec 25, 2003
333
HK
Hi there,

Say I just setup w2k3 server with AD, & now I want to create 50 user accounts.

Instead of using GUI to create 1 by 1, can I use some text file to prepare the user data, then import into AD & create 50 user accounts at 1 time?

If so, can you tell me how to do?

Many thanks!
 
Put your user data into an Excel file and you can use a script I wrote.

You will need to modify the script for your network with your domain name and also edit the LDAP path for your server. The top of the script tells you what headings to use in Excel so you know what data goes where.

Enjoy.

Code:
'==========================================================================
'
' NAME: createNewUsers.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 04/21/2003
' COPYRIGHT 2003 The Spider's Parlor, All Rights Reserved
'
' COMMENT: 
' Creates users based on Excel spreadsheet information.
' Excel spreadsheet  formatting:
' Row 1 to have headings
' Column A (1) to have login
' Column B (2) to have first_name 
' Column C (3) to have last_name  
' Column D (4) to have phone      
' Column E (5) to have extension  
' Column F (6) to have fax        
' Column G (7) to have email      
' Column H (8) to have street     
' Column I (9) to have suite     
' Column J (10) to have city  
' Column K (11) to have state      
' Column L (12) to have zip    
'=====================================

set x = getobject(,"excel.application")
r = 2

Const c = "US"
Const co = "UNITED STATES"
'Change the following with your company info
Const company = "Company XYZ"
Const ou_name = "Users"

do until len(x.cells(r, 1).value) = 0

    login      = x.cells(r, 1).value
    first_name = x.cells(r, 2).value
    last_name  = x.cells(r, 3).value
    phone      = x.cells(r, 4).value
    extension  = x.cells(r, 5).value
    fax        = x.cells(r, 6).value
    email      = x.cells(r, 7).value
    street     = x.cells(r, 8).value
    suite      = x.cells(r, 9).value
    city       = x.cells(r, 10).value
    state      = x.cells(r, 11).value
    zip    =cstr(x.cells(r, 12).value)


    
'Change the following with the proper LDAP path for your network.
    set o = getobject("LDAP://SERVER.XYZ.com.local/CN=Users,DC=XYZ,DC=com,DC=local")

    if err then
        x.cells(r, 15).value = err.number & ":  " & err.description
        err.Clear
    end if
    

   Set oUser = o.Create("user","CN=" & Cells(r,1).Value)
   For j = 2 To Columns.Count

	if len(Cells(r,j).Value) = 0 then 
       Cells(r,j).Value = " " 
    end If

    if fn + ln = 0 then 
       fullName = x.cells(r, 1).value 
    else 
       fullName = first_name & " " & last_name
    end if



     oUser.Put Cells(1,j).Value, Cells(r,j).Value
     oUser.SetInfo
   Set oUser = Nothing
   Next

  
  
            
	
    


	
    Set oUser = o.Create("user","CN=" & fullName)
    oUser.Put "sAMAccountName", login
    oUser.SetInfo
    oUser.Put "userPrincipalName", email
    oUser.SetInfo
    oUser.Put "c", c
    oUser.Put "co", co
    oUser.Put "company", company
    oUser.Put "displayName", first_name & " " & last_name
    oUser.Put "facsimileTelephoneNumber", fax
    oUser.Put "givenName", first_name
    oUser.SetInfo
    oUser.Put "l", "Phoenix"
    oUser.Put "mail", email
    oUser.Put "mailNickname", login
    'oUser.Put "name", first_name & " " & last_name
    oUser.Put "otherTelephone", "Ext. "& extension
    oUser.Put "postalCode", zip
    oUser.SetInfo
    oUser.Put "sn", last_name
    oUser.Put "st", state
    oUser.Put "streetAddress", street & vbCrLf & Suite
    oUser.Put "telephoneNumber", phone & "Ext. "& extension
    oUser.SetPassword login
    oUser.SetInfo
    oUser.AccountDisabled = False
    oUser.SetInfo
	

    If Err.Number <> 0 And Err.Number <> -2147019886 Then
        x.cells(r, 15).value = err.number & ":  " & "ID creation error"
    Else

    x.cells(r, 15).value = "created"
        end if


    r = r + 1
    

    set objOU = Nothing
    set oUser = Nothing    
    set o = nothing
Err.Clear
Loop


set x = nothing

msgbox "done"

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Hi markdmac, thx so much for your prompt response!

I'll try to 'digest' it & see how it goes!
 
Hi markdmac,

Sorry for the late reply. I need your help again!

When running the above script, I got a "windows script host" prompt as follows:
Script: c:\temp\createuser.vbs
line: 27
char: 1
error: ActiveX component can't create object: 'getobject'
code: 800A01AD
source: microsoft vbscript runtime error

As I don't know much about vbscript, I've no idea what's going on. Could you please help to check for me?

Sorry for keep on bothering you & million thanks in advance!
 
Hi mark saw this post and wondered if yo could help me.

I need a script to add users to my Domain
Ok I know what you are going to say "use script above"
however I think my needs could be done with a simpler code

My DOMAIN is bungaymiddle.local
The container is pupils
password password
The users have numbers in sequence ie 2001 2002 2003 etc
I was thinking along the lines of a script that asked for the year ie 2001 and number of users and would then loop putting the users in with a default password until it reached the end number.
You have been of great help to me and my school before with code scripts
Thanks for any ideas on this one


Some lead, some follow....I just Hope! :)
 
Hi itsfisko,

I remember your other project, had to do with timing the login if I recall correctly.

Anyway, you surmised correctly. Rather than rewriting an entire script, I would suggest that you simply use Excel to autofill in your user names and just use the script above.



I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Thanks mark, the other project was not mine. However I will use the above with an EX vbs and try that Cheers

Some lead, some follow....I just Hope! :)
 
Hi Mark,
I have tried using your script, changed the info etc but I get a failure at line 61 char 4 mismatch 'cells'
any ideas
ps i am unsure if I changed the

Cont company = what goes here?
and on the LDAP path where it says
"LDAP:// server.XYZ.com.local etc what do I do here if my domain is bungaymiddle.local?
Thanks once again John.

Some lead, some follow....I just Hope! :)
 
Cont company = what goes here? Put your company name here to be filled into the user properties
and on the LDAP path where it says
"LDAP://server.XYZ.com.local etc what do I do here if my domain is bungaymiddle.local?
"LDAP://server.bungaymiddle.com.local
Note: replace "Server" with the name of your server.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top