Hi all,
I am trying to create users in a specific OU, which should be read from a csv file.
This is a line from the csv:
AAipuk1111,Aai,Puk,Welkom2012,HVServ.local,Users,Aai Puk,TopOU,SubOU
VBS script:
I get errorcode 0x80005000 (line with Set 0Container)
Anyone can help me with this?
I need ot import about 150 users, divided over 13 OU's
CSV file is ready, and I need this next week to work!
So please give me a clue..
Thanks
Office 2010
I am trying to create users in a specific OU, which should be read from a csv file.
This is a line from the csv:
AAipuk1111,Aai,Puk,Welkom2012,HVServ.local,Users,Aai Puk,TopOU,SubOU
VBS script:
Code:
' ---------------------------------------------------
' Script: createusers2.vbs
' Input: It uses a CSV file with layout logonname,firstname,lastname,password
Option Explicit
Dim sCSVFileLocation
Dim sCSVFile
Dim objFSO
Dim objFile
Dim strLine
Dim strItems
Dim oNewUser
' ----------LDAP connection variables----------
Dim oRootLDAP
Dim oContainer
Dim sOU1
Dim sOU2
' ----------Other variables--------------------
Dim sLogon
Dim sFirstName
Dim sLastName
Dim sDisplayName
Dim sPassword
Dim nPwdLastSet
Dim nUserAccountControl ' Used to enable the account
Dim sDomain
Dim sEmailaddress
' ----------Modify this to match your company's AD domain----------
sDomain="HVServ.local"
' ----------Input file location----------
sCSVFileLocation = "C:\ServShare\Bulk\"
' ----------Full path to input file----------
sCSVFile = sCSVFileLocation&"test.csv"
' ----------Commands used to open the CSV file and select all of the records----------
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile(sCSVFile, 1)
' ----------Create a connection to the Active Directory Users container.----------
'Eerst domeinnaam, OU, top OU, domeinnaam gesplitst
Set oContainer = GetObject("LDAP://HVServ.local/OU=" & sOU2 & ",OU=" & sOU1 & ",OU=Examen,OU=leerling,dc=HVServ,dc=local")
'Set oContainer = GetObject("LDAP://HVServ.local/OU=BB-BTT,OU=BB,OU=Examen,OU=Leerling,dc=HVServ,dc=local")
'When I use this second line, it works fine
' ----------Allows processing to continue even if an error occurs (i.e. dup user)----------
on error resume next
Do Until objFile.AtEndOfStream ' Reads the values (cells) in the sInputFile file.
' --------- Start creating user account----------
' Read variable information from the CSV file
' and build everything needed to create the account
strLine = objFile.ReadLine
strItems = split(strLine, ",")
sLogon = strItems(0)
sFirstName = strItems(1)
sLastName = strItems(2)
sDisplayName = strItems(6)
sPassword = strItems(3)
sOU1 = strItems(7)
sOU2 = strItems(8)
' ----------Build the 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 this information into Active Directory so we can----------
' modify the password and enable the user account
oNewUser.SetInfo
' ----------Change the users password----------
oNewUser.SetPassword sPassword
oNewUser.Put "pwdLastSet", -1
' ----------Enable the user account----------
oNewUser.Put "userAccountControl", 512
oNewUser.SetInfo
Loop
objFile.Close
' ----------Used only for debugging----------
if err.number = -2147019886 then
msgbox "User logon " & sLogon & "already exists"
End If
' --------- End of user account creation----------
Anyone can help me with this?
I need ot import about 150 users, divided over 13 OU's
CSV file is ready, and I need this next week to work!
So please give me a clue..
Thanks
Office 2010