Question

Locked

Importing users into AD using VBS Script and CSV File

By scott_langshaw2 ·
Hey guys

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

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

TR link

by unhappyuser In reply to Importing users into AD u ...

Check out this TR link.

EMD

Collapse -

Would that they were all this easy

by neilb@uk In reply to Importing users into AD u ...

You need to step through your RecordSet.

At the moment, you're just sitting in the loop at the first record. Use the oRecordset.MoveNext method just above the Loop statement.

:)

Collapse -

Worked

by scott_langshaw2 In reply to Would that they were all ...

Thanks Neil it has worked a treat thanks for your help

:)

Back to Software Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums