• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

Effective ways to create multiple users at once.

What are the most effetive ways people use to create multiple user accounts at once?  Ive read about programs or scripts that read off of a text or excel file, but I'm not really sure where to start.  Is a script the best place to start, or are there better utilites to use?  All help would be appreciated.
0
Go-GBS
Asked:
Go-GBS
2 Solutions
 
exx1976Commented:
I use VBS to batch create accounts from an Excel file.  I work for a call center company, so turnover is quite high.  There are ~15 new employees every Monday.

Plus, by creating the accounts with a script, they are all uniform.  No mispellings in address or phone number, never "forget" to add them to a security group, etc etc.  They are always set up exactly the same.
0
 
Go-GBSAuthor Commented:
Where could I look for a script like this.
0
 
gratex_ssdCommented:
try to search at Technet script center

http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct08/hey1020.mspx

but why VBS -> there is better scripting posibility from MS -> powershell...
0
 
exx1976Commented:
User Creation scripts are VERY customized for the environment in which they are used..  Username naming conventions, addresses, phone numbers, group membership, OU's, etc etc..

I can help you out with the basic mechanics, but you're going to need to either learn a little VBS, or reveal a LOT of specifics about your AD...

Here's a generic one.  I think I scrubbed out everything from my domain.  I can't guarantee it'll work, as it was a quick scrub job (besides, you need to enter the info for your domain), but this is a good starting point.  It expects an excel spreadsheet names users.xls in the same directory as the script.  The first row should be a header record (the script skips it), column A should be last name, column b first name, and column c employee ID number.  This script creates accounts as firstname.lastname for the login name, and the default password is "Password".  Further, it sets the login hours by copying them from a user named jdoe in the MyUsers OU.

After it runs, it scrubs the spreadsheet so it can be used again.

There's also a bunch of stuff in here for configuring Terminal Server settings (we use Citrix).

There should be sufficient notes in there to allow you to figure most of it out.


HTH,
exx
sPath = WScript.ScriptFullName
'WScript.Echo sPath
sPath = Left(sPath,Len(sPath)-Len(WScript.ScriptName))
Set oFS = CreateObject("Scripting.FileSystemObject")
' create Excel
Set oExcelApp = CreateObject("Excel.Application")
' get the Users.xls file and set a reference to the workbook
Set oWorkbook = oExcelApp.Workbooks.Open(sPath & "users.xls")
' get a reference to the 1st worksheet and activate it
Set oWorksheet = oWorkbook.Worksheets(1)
oWorksheet.Activate
' make Excel invisible
oExcelApp.Visible = False
Dim ArrVals(2)
bEmpty = False
iCounter = 2
Do Until bEmpty = True
	EmptyCounter = 0
	For q = 0 To 2  'skips incomplete records
		ArrVals(q) = ""
		ArrVals(q) = oWorksheet.Cells(iCounter, q + 1)
		If ArrVals(q) = "" Then EmptyCounter = EmptyCounter + 1
	Next
	If EmptyCounter = 0 Then
    ' add a user passing down the values from the cells
    	AddUser ArrVals(0), ArrVals(1), ArrVals(2)
    	iCounter = iCounter + 1
    End If
    If EmptyCounter = 3 Then bEmpty = True
Loop
If iCounter = 2 Then 
	oWorkbook.Save
	oExcelApp.Quit
	WScript.Quit()
End If
bEmpty = False
iCounter = 2
Do Until bEmpty = True
	strUser = oWorksheet.Cells(iCounter, 1)
	if strUser = "" Then
		bEmpty = True
	Else
		oWorksheet.Cells(iCounter, 1).Value = ""
		oWorksheet.Cells(iCounter, 2).Value = ""
		oWorksheet.Cells(iCounter, 3).Value = ""
		iCounter = iCounter + 1
	End If
Loop
oWorkbook.Save
oExcelApp.Quit
WScript.Quit 
 
 
Sub AddUser(byVal sLastName, byVal sFirstName, ByVal sID)
	
	ReportedFullName = sFirstName & " " & sLastName
	sLastName = strip(sLastName)
	sFirstName = strip(sFirstName)
	sFirstName = UCase(Left(sFirstName,1)) & LCase(Right(sFirstName, Len(sFirstName)-1))
	sLastName = UCase(Left(sLastName,1)) & LCase(Right(sLastName, Len(sLastName)-1))
	Set oOU = GetObject("LDAP://OU=MyUsers,DC=MyDomain,DC=local")
	sUserName = sFirstname & "." & sLastName
	' create user
	Set oUSR = oOU.Create("user", "CN=" & sUserName)
	'set the properties of the new user
	oUSR.Put "samAccountName", cstr(sUserName)
	oUSR.Put "givenname", cstr(sFirstName)
	oUSR.Put "sn", cstr(sLastName)
	oUSR.put "displayName", CStr(sFullName)
	oUSR.put "co","country"
	oUSR.put "countryCode",840
	oUSR.put "l","city"
	oUSR.put "physicalDeliveryOfficeName","city"
	oUSR.put "postalCode","zipcode"
	oUSR.put "st","state"
	oUSR.put "streetAddress","title"
	oUSR.put "title","title"
	oUSR.put "userPrincipalName",sUserName & "@MyDomain.local"
	oUSR.put "company", "companyname"
	oUSR.put "department", "blahblah"
	oUSR.put "description", "title"
	oUSR.put "division" , "city"
	oUSR.put "telephoneNumber" , "212-555-1212"
	oUSR.put "employeeID" , CStr(sID)
	oUSR.SetInfo
	'msgbox sUserName & " created successfully"
	'Set user default password
	oUSR.SetPassword "Password"
	'force user to change password at first login
	oUSR.Put "pwdLastSet", CLng(0)
	'unlock account (accounts are created disabled by default)
	oUSR.AccountDisabled = False
	oUsr.AllowLogon = 0   							' Disabled = 0, Enabled = 1
	oUsr.EnableRemoteControl = 0					' EnableRemoteControl Values:
   	                                    			' Disable               = 0
   	                                    			' EnableInputNotify     = 1
   	                                    			' EnableInputNoNotify   = 2
   	                                    			' EnableNoInputNotify   = 3
   	                                    			' EnableNoInputNoNotify = 4
	oUsr.BrokenConnectionAction = 0      			' Disconnect = 0, End Session = 1
	oUsr.MaxConnectionTime = 0		  		 		' Time in minutes
	oUsr.MaxDisconnectionTime = 0			    	' Time in minutes
	oUsr.MaxIdleTime = 0 					    	' Time in minutes
	oUsr.ReconnectionAction = 0 		     		' Any Client = 0, Originating client = 1
	oUsr.ConnectClientDrivesAtLogon = 0		  		' Disabled = 0, Enabled = 1
	oUsr.ConnectClientPrintersAtLogon = 0 		   	' Disabled = 0, Enabled = 1
	oUsr.DefaultToMainPrinter = 1					' Disabled = 0, Enabled = 1
	oUsr.TerminalServicesInitialProgram = ""
	oUsr.TerminalServicesWorkDirectory  = ""
	oUsr.TerminalServicesProfilePath = "C:\profile\user"
	'the next three lines get the logon hours from the user jdoe and apply it to the new user
	Set oUser = GetObject ("LDAP://CN=jdoe,OU=MyUsers,DC=MyDomain,DC=local")
	oUser.GetInfo
	hours = oUser.LogonHours
	oUSR.put "LogonHours",hours
	oUSR.SetInfo
End Sub
 
 
function strip(text)
	text = Trim(text)
	index = Len(text)
	For i = 1 To index
		temp = Left(text,i)
		If right(temp,1) = "." Or right(temp,1) = " " Or right(temp,1) = "-" or right(temp,1) = "'" Then
			If i = 1 Then temp = Right(text,Len(text)-i)
			If i > 1 Then temp = Left(text,i-1) & Right(text,Len(text)-i)
			text = temp
			index = Len(text)
			if i > 2 Then i=i-2
		End If
	Next
	strip = text
End Function

Open in new window

0
 
BSonPoshCommented:
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Tackle projects and never again get stuck behind a technical roadblock.
Join Now