Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[green]'==========================================================================
'
' NAME: SimpleCreateUsersFromExcel.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE : 7/1/2007
' COPYRIGHT (c) 2007 All Rights Reserved
'
' COMMENT:
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS
' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
' OF THIS CODE OR INFORMATION.
'
'==========================================================================
'Bind to the open Excel spreadsheet[/green]
Set xl = GetObject(,"Excel.Application")
[green]'Assume the Excel spreadsheet has a header row[/green]
xlRow = 2
[green]
'Get the AD Domain info Example: DC=SPIDERSPARLOR,DC=COM[/green]
Set oRootDSE = GetObject("LDAP://RootDSE")
oDomain = oRootDSE.Get("DefaultNamingContext")
[green]
'Specify container or OU to create new accounts in (Default container shown below)[/green]
Set objOU = GetObject("LDAP://CN=Users," & oDomain)
[green]
'Now read from Excel and create the users[/green]
do until len(xl.cells(xlRow, 1).value) = 0
login = xl.cells(xlRow, 1).value
first_name = xl.cells(xlRow, 2).value
last_name = xl.cells(xlRow, 3).value
password = xl.cells(xlRow, 4).value
Set objUser = objOU.Create("User", "cn=" & login)
objUser.Put "sAMAccountName", login
objUser.SetInfo
oUser.Put "givenName", first_name
oUser.Put "sn", last_name
objUser.SetInfo
oUser.SetPassword password
oUser.SetInfo
oUser.AccountDisabled = False
oUser.SetInfo[green]
'Now require user to change the password[/green]
objUser.Put "pwdLastSet", 0
objUser.SetInfo
[green]'increment the row number[/green]
xlRow = xlRow + 1
loop
Const adOpenStatic = 3
Const adLockOptimistic = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
"Provider = Microsoft.Jet.OLEDB.4.0; " & _
"Data Source = 'C:\Scripts\Test.mdb'"
sqlQuery = "Select * from Table1"
objRecordSet.Open sqlQuery , _
objConnection, adOpenStatic, adLockOptimistic
Do Until objRecordset.EOF
UserName = objRecordset("UserName")
FirstName = objRecordset("FirstName")
LastName = objRecordset("LastName")
Password = objRecordset("Password")
Wscript.Echo UserName
WScript.Echo FirstName
WScript.Echo LastName
WScript.Echo Password
Wscript.Echo
objRecordset.MoveNext
Loop
On Error Resume Next
'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("sourcefile.csv")
'make an array from the data file
DataList = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each Line In DataList
LineArray = Split(Line,";")
login = LineArray(0)
first_name = LineArray(1)
last_name = LineArray(2)
password = LineArray(3)
[green] 'Worker process code goes here.[/green]
Next