I have purchased a book titled: "Microsoft Vbscript Step by Step" that has a sample script to import multiple user accounts from a "csv" file. My question is; why does the script create the account, but not populate the account with the other information? For example, the account will get created. But when you go to Active Directory, and right-click the account and view its properties, on the "General" tab, the information there is blank. In the script it has all the information there that should be populated. Why is it not populating? Any help that anyone can give me will be greatly appreciated.
----------------------------------------------------------
Start of script
----------------------------------------------------------
On Error Resume Next
Dim objFSO,objTS
Dim objDom,objUser
Const FORREADING=1
strFile="newusers.csv"
'format of newusers.csv
'givenname,sn,password,telephonenumber,upnsuffix
'example:
'Jeff,Hicks,P@sswordJH,555-1234,@jdhitsolutions.com
'Don,Jones,$cr1pting@nsw3rs,555-1234,@scriptinganswers.com
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objTS=objFSO.OpenTextFile(strFile,FORREADING)
Set objDom=GetObject("LDAP://OU=Consultants,DC=Company,DC=pri")
'open text file and process user data on each line
Do while objTS.AtEndofStream<>True
rline=objTS.readline
UserArray=Split(rline,",")
strFirst=UserArray(0)
strLast=UserArray(1)
strUser=strFirst & " " & strLast
strLogon=Left(strFirst,1)&strLast
strUsername=LCASE(Left(strFirst,1)&strlast)
strPass=UserArray(2)
strPhone=UserArray(3)
strUPN=strUserName & UserArray(4)
'Create user object
Set objUser=objDom.Create ("User","cn="&strUser)
objUser.Put "samAccountName",strUserName
objUser.SetInfo
'Now that user object is created, let's set some properties
objUser.Put "givenname",strFirst
objUser.Put "sn",strLast
objUser.Put "displayname",strFirst & " " & strLast
objUser.Put "UserPrincipalName",strUPN
objUser.Put "AccountDisabled",FALSE
objUser.Put "TelephoneNumber",strPhone
objUser.SetPassword(strPass)
objUser.SetInfo
Loop
objTS.Close
WScript.Quit
----------------------------------------------------------
End of script
----------------------------------------------------------
by: Chris-DentPosted on 2007-06-14 at 09:51:20ID: 19285092
I imagine it's because of this one:
objUser.Put "AccountDisabled",FALSE
There's no such attribute so setting it to false will generate an error.
Because of the "On Error Resume Next" at the start you won't see that error and it'll continue on creating accounts. But failing to set the information and the password.
Chris