csv - VBScript Error 80040E14 Syntax error in FROM clause -
i'm trying use script found on internet allow bulk creation of new user accounts in active directory using vbscript , csv file. i'm not using csvde b/c script create passwords. keep encountering error when running code cannot figure out. can help?
'********************************************************************* ' script: createusersfromcsv.vbs * ' creates new user accounts in active directory csv file. * ' input: csv file layout logonname,firstname,lastname,password * ' * '********************************************************************* option explicit dim scsvfilelocation dim scsvfile dim oconnection dim orecordset dim onewuser ' variables needed ldap connection dim orootldap dim ocontainer ' holding variables information import csv file dim slogon dim sfirstname dim slastname dim sdisplayname dim spassword dim npwdlastset dim nuseraccountcontrol ' used enable account dim sdomain dim scompany dim sphone dim semail dim sdescription dim numchar, count, strrdm, intrdm dim fso, f, fso1, f1 '* modify match company's ad domain sdomain="mydomain.local" '* input file location scsvfilelocation = "c:\documents , settings\administrator\desktop\" 'keep trailing slash! '* full path input file scsvfile = scsvfilelocation&"newusers.csv" ' commands used open csv file , select of records set oconnection = createobject("adodb.connection") set orecordset = createobject("adodb.recordset") oconnection.open "provider=microsoft.jet.oledb.4.0;data source= " & _ scsvfilelocation & ";extended properties=""text;hdr=no;fmt=delimited""" orecordset.open "select * " & scsvfile ,oconnection ' create connection active directory ou container. set orootldap = getobject("ldap://rootdse") set ocontainer = getobject("ldap://ou=test," & _ orootldap.get("defaultnamingcontext")) on error resume next until orecordset.eof ' reads values (cells) in sinputfile file. ' --------- start creating user account ' read variable information csv file ' , build needed create account slogon = orecordset.fields.item(0).value sfirstname = orecordset.fields.item(1).value slastname = orecordset.fields.item(2).value sdisplayname = sfirstname&" "&slastname spassword = orecordset.fields.item(3).value ' build user account set onewuser = ocontainer.create("user","cn="&sfirstname&" "&slastname) onewuser.put "samaccountname",lcase(slogon) onewuser.put "givenname",sfirstname onewuser.put "sn",slastname onewuser.put "userprincipalname",lcase(slogon)&"@"&sdomain onewuser.put "displayname",sdisplayname onewuser.put "name",lcase(slogon) ' write information active directory can ' modify password , enable user account onewuser.setinfo ' change users password onewuser.setpassword spassword onewuser.put "pwdlastset", 0 ' enable user account onewuser.put "useraccountcontrol", 512 onewuser.setinfo objfile.close '******************* orecordset.movenext loop '******************* ' used debugging 'if err.number = -2147019886 ' msgbox "user logon " & slogon & "already exists" 'end if ' --------- end of user account creation
here error occuring, line 51 char 1:
orecordset.open "select * " & scsvfile ,oconnection
maybe scsvfile
contains special characters , therefore must escaped this:
orecordset.open "select * [" & scsvfile & "]", oconnection
i hope helps.
Comments
Post a Comment