Im new on here. Im having a few problems with this script it reads the csv file fine but only reads the first user and then stops and doesnt carry on reading the csv file.
Any ideas here is the script:
Dim sCSVFileLocation, sCSVFile, oConnection, oRecordSet, oNewUser, oRootLDAP, oContainer, sLogon, sFirstName, sLastName Dim sDisplayName, sPassword, nPwdLastSet, nUserAccountControl, sDomain
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
Importing users into AD using VBS Script and CSV File
Im new on here. Im having a few problems with this script it reads the csv file fine but only reads the first user and then stops and doesnt carry on reading the csv file.
Any ideas here is the script:
Dim sCSVFileLocation, sCSVFile, oConnection, oRecordSet, oNewUser, oRootLDAP, oContainer, sLogon, sFirstName, sLastName
Dim sDisplayName, sPassword, nPwdLastSet, nUserAccountControl, sDomain
sDomain ="swdomain.local"
sCSVFileLocation = "C
sCSVFile = sCSVFileLocation&"year6.csv"
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 * FROM " & sCSVFile ,oConnection
Set oRootLDAP = GetObject("LDAP://rootDSE")
Set oContainer = GetObject("LDAP://cn=Users," & _
oRootLDAP.Get("defaultNamingContext"))
On Error Resume Next
do until oRecordSet.EOF
sLogon = oRecordSet.Fields.Item(0).value
sFirstName = oRecordSet.Fields.Item(1).value
sLastName = oRecordSet.Fields.Item(2).value
sDisplayName = sLastName&", "&sFirstName
sPassword = oRecordSet.Fields.Item(3).value
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)
oNewUser.SetInfo
oNewUser.SetPassword sPassword
oNewUser.Put "pwdLastSet", 0
oNewUser.Put "userAccountControl", 512
oNewUser.SetInfo
Loop
Any help appreciated