I am running server 2008. regardless of the script I run I can not get it to create multiple users. i even took my 2003 scripts and changed the names and it would not create the users. i am trying to run the script that creates the users, and set the home dir and also the profile dir. i am pulling the info from a .csv file.
Software/Hardware used:
ASKED:
July 14, 2009 8:29 PM
UPDATED:
February 28, 2012 6:46 AM
And the script you are running is?
'****************************************************************************************** '* User Add Account Script '* '* Purpose: Adds a new user to Active Directory. Adds username, first name, last name '* display name, description, email, web page, user logon name, user logon name '* pre-Windows 2000, User Must Change Password On Next Logon, profile path, '* home drive, home directory. The script can be passed the six attributes '* for the account or the name of a file with the attributes. '* If no command line arguments are given, the user is prompted for them. '* If the user enters a blank in the text box the script exits. '* '* Note: Does not set Unix attributes. Does not put account in the proper OU. '* '* Pre-Conditions: If using a textfile for input, it must exist. '* '* Post-Condition: The user account is created in the "Users" container. They must be moved '* to the proper OU. The unix settings are not set and the Home Directory '* has not been created on Humongo. '* '* Expects: username, first name, last name, description, password, bin '* -or- '* filename '* -or- '* nothing. '* '* Returns: Nothing '* '* Exceptions: If the user exists, the script shows the username(s), logs them to the '* "ProcessedUsers.txt" file, does not try to add the user and continues. '* If 0,1 or 6 arguments are not given, the script notifies the user and quits. '* '* Edited on 3/7/2004 Kurt Mosiejczuk '* Made useable on 3/10/2004 by Rick Tolleson '* -Skips any entry with a username of 'username'. This facilitates using the same '* file for Mail Merge and account creation '* -Corrected ProcessFile to use the order stated above. Before it lied and shuffled '* username, last name and first name. '****************************************************************************************** '--------------------------------------------------------------------------------- 'Variable Declarations '--------------------------------------------------------------------------------- dim objOU 'The OU object dim objUser 'The User object dim username dim lastname dim firstname dim passwd 'The password in their username dim description 'Description Property 'dim bin 'The subdir off of home where their home dir is, 'for example \humongohomeXXusername where XX is bin dim fso 'File System object dim logfile 'File handle for the logfile dim objArgs 'Command line arguments '--------------------------------------------------------------------------------- 'Main Body of Scipt '--------------------------------------------------------------------------------- 'Put the command line arguments into the objArgs variable Set objArgs = WScript.Arguments 'If there are no command line arguments then prompt the user for them. if objArgs.Count = 0 then PromptForInfo() CreateUser() 'If there is 1 command line argument then assume it's a file name. elseif objArgs.Count = 1 then ProcessFile() 'If there are 6 command line arguments then use them and don't prompt elseif objArgs.Count = 5 then lastname = objArgs(0) firstname = objArgs(1) username = objArgs(2) description = objArgs(3) passwd = objArgs(4) 'bin = objArgs(5) CreateUser() else WScript.Echo "The wrong number of arguments were supplied." Wscript.quit end if '--------------------------------------------------------------------------------- 'Functions and Subroutines '--------------------------------------------------------------------------------- Function PromptForInfo() 'Prompt for Username username = InputBox ("Enter username", UserName) If username = "" Then WScript.Echo "Canceled by the user" Wscript.quit End If 'Prompt for First Name firstname = InputBox("Enter FirstName") If firstname = "" Then WScript.Echo "Canceled by the user" Wscript.quit End If 'Prompt for Last Name lastname = InputBox("Enter lastname") If lastname = "" Then WScript.Echo "Canceled by the user" Wscript.quit End If 'Prompt for Description description= InputBox("Enter Description (ex.VCSE created in 20032)") If description= "" Then WScript.Echo "Canceled by the user" Wscript.quit End If 'Prompt for Password passwd = InputBox("Enter Password") If passwd= "" Then WScript.Echo "Canceled by the user" Wscript.quit End If 'Prompt for Bin Number 'bin = InputBox("Enter Bin Number") 'If bin = "" Then ' WScript.Echo "Canceled by the user" ' Wscript.quit 'End If End Function '--------------------------------------------------------------------------------- Function ProcessFile() 'Reads the arguments from a textfile Dim myArray 'Get a FileSystemObject for manipulating the filesystem Set objfso = Wscript.CreateObject("Scripting.FileSystemObject") 'Open the file for reading Set accountsFile = objfso.OpenTextFile(objArgs(0),1) 'Loop until you reach the end of the file Do While False = accountsFile.AtEndOfStream 'Read in a line and split it by commas into an array myArray = split(accountsFile.ReadLine,",") username = myArray(2) firstname = myArray(1) lastname = myArray(0) description = myArray(3) passwd = myArray(4) 'bin = myArray(5) If username <> "UserName" Then CreateUser() End If loop accountsFile.Close() End Function '------------------------------------------------------------------------------------------- Function DoesAccountExist() 'Determines if an account exists in ActiveDirectory Dim objConnection Dim objCommand 'Sets up the connection to ActiveDirectory Set objConnection = CreateObject("ADODB.Connection") objConnection.Open "Provider=ADsDSOObject;" Set objCommand = CreateObject("ADODB.Command") objCommand.ActiveConnection = objConnection 'The query. This filters it to only look for users objCommand.CommandText = _ "<GC://dc=eecc,dc=ce,dc=rit,dc=edu>;" & _ "(&(objectCategory=person)(objectClass=user)" & _ "(sAMAccountName="& username &"));" & _ "sAMAccountName, distinguishedName;subtree" 'Executes the query Set objRecordSet = objCommand.Execute 'If nothing is returned by the query then the user must not exist If objRecordSet.RecordCount = 0 Then DoesAccountExist = "NO" Else DoesAccountExist = "YES" 'Loop though the results of the query and output to screen and log While Not objRecordset.EOF Wscript.Echo "User already exists " & "sAMAccountName = " & _ objRecordset.Fields("sAMAccountName") & chr(13), "Major: " & description objRecordset.MoveNext Wend End If 'Close the connection objConnection.Close End Function '------------------------------------------------------------------------------------------- Sub CreateUser() 'Creates the user account in ActiveDirectory 'If the account does not exist then create it If DoesAccountExist = "NO" then 'Get a handle for AD Set objOU = GetObject("LDAP://dc=eecc,dc=ce,dc=rit,dc=edu") Set objRootDSE = GetObject("LDAP://rootDSE") Set objContainer = GetObject("LDAP://cn=Users," & _ objRootDSE.Get("defaultNamingContext")) Set objLeaf = objContainer.Create("Users", "cn=" & username) objLeaf.Put "sAMAccountName", username objLeaf.Put "userPrincipalName", username objLeaf.Put "displayName", lastname & "," & " " & firstname objLeaf.Put "givenName", firstname objLeaf.Put "sn", lastname ' objLeaf.Put "description", description Dim description Select Case description Case eecc objLeaf.Put "profilePath", "\butlerstudent_homeeecc" & username objLeaf.Put "homeDrive", "x:" objLeaf.Put "homeDirectory", "\butlerstudent_dataeecc" & username objLeaf.Put "mail", username & "@rit.edu" objLeaf.Put "wWWHomePage", "http://www.ce.rit.edu" Case eeee objLeaf.Put "profilePath", "\butlerstudent_homeeeee" & username objLeaf.Put "homeDrive", "x:" objLeaf.Put "homeDirectory", "\butlerstudent_dataeeee" & username objLeaf.Put "mail", username & "@rit.edu" objLeaf.Put "wWWHomePage", "http://www.ee.rit.edu" Case emcr objLeaf.Put "profilePath", "\butlerstudent_homeemcr" & username objLeaf.Put "homeDrive", "x:" objLeaf.Put "homeDirectory", "\butlerstudent_dataemcr" & username objLeaf.Put "mail", username & "@rit.edu" objLeaf.Put "wWWHomePage", "http://www.rit.edu/kgcoe/ue/" Case Else objLeaf.Put "profilePath", "\butlerstudent_homeother" & username objLeaf.Put "homeDrive", "x:" objLeaf.Put "homeDirectory", "\butlerstudent_dataother" & username objLeaf.Put "mail", username & "@rit.edu" objLeaf.Put "wWWHomePage", "http://www.ce.rit.edu" 'Write the information out to ActiveDirectory ObjLeaf.SetInfo End Select ' 'Write the information out to ActiveDirectory ObjLeaf.SetInfo 'Set the password objLeaf.setPassword(passwd) 'Sets the account to not expire? objLeaf.Put "userAccountControl", 1 'Set it so the user must change their password on the next logon objLeaf.Put "pwdLastSet", 0 'Write the information out to ActiveDirectory ObjLeaf.SetInfo Else 'Don't create the user. 'Change passwd to indicate existance passwd = "EXISTING ACCOUNT" End If LogProcessedUsers() End Sub '------------------------------------------------------------------------------------------------ Sub LogProcessedUsers() 'Writes the existing username to a file 'Get a FileSystemObject for manipulating the filesystem Set fso = Wscript.CreateObject("Scripting.FileSystemObject") 'If the file exists, open it for appending If (fso.FileExists("ProcessedUsers.txt")) Then Set logfile = fso.OpenTextFile("ProcessedUsers.txt", 8) Else 'If the file does not exist, create it for writing Set logfile = fso.CreateTextFile("ProcessedUsers.txt", 2) End If 'Write a line to the file logfile.WriteLine(username & "," & firstname & "," & lastname & "," & description & "," & passwd & "," & bin) 'Close the file logfile.Close() End Sub '------------------------------------------------------------------------------------------------ 'End of Scriptany luck looking at the script?
Download this file and try..
http://hotfile.com/dl/148029393/c50b337/Creare_Bulk_Users_in_AD.zip.html