Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AD script -- data input from a text or csv file 1

Status
Not open for further replies.

mirty12

Technical User
Jun 6, 2002
20
US
Oh wise VB Gurus... How can I modify this script, which creates a user in a Windows 2000 Active Directory, to accept data input from a text or HTML file?

That is, for the user name, given name, etc., it would look at fields in the file and fill it in from there.

This is the code:

'*Script to create user *
'************************

Set ou = GetObject("LDAP://OU=DEP_IT,DC=AUS,DC=mycompany,DC=com")
Set usr = ou.Create("user", "CN=Joe Smith")

'--- Mandatory Attributes----
usr.Put "samAccountName", "JSmith"

'---- Optional Attributes, you can optionally skip these----
usr.Put "sn", "Smith"
usr.Put "givenName", "Joe"
usr.Put "userPrincipalName", "Joe.Smith2@mycompany.com"
usr.Put "telephoneNumber", "(512) 123 4567"
usr.Put "title", "IT Gineau Pig"
usr.SetInfo

'--Now that the user is created, reset the user's password and
'--enable its account

usr.SetPassword "dummy"
usr.AccountDisabled = False
usr.SetInfo

********************************************

Your help much appreciated...
 
Here is one that I use all the time, I regularly use this to add 6700 users into a test environment - takes about 3 mins to add the users.

you will need to create a txt file in the format

Lastname,Firstname,Userid,Password

You can obviously expand on this, it does require the comma between fields as it uses that to split the line into an array.

Const ForReading = 1
Const ADS_PROPERTY_UPDATE = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Wscript.Arguments.Count = "0" Then
msgbox "Please enter Create_Users_In_AD.VBS nameoftext file to read" & VbCrlf & "Example: Create_Users_In_AD.vbs A:\userlist.txt"
Wscript.Quit
End If
textfile = Wscript.Arguments(0)
If objfso.FileExists(textfile) = False Then
Msgbox "Unable to find input file"
Wscript.Quit
End If
Set objTextFile = objFSO.OpenTextFile _
(textfile, ForReading)
Set oRootDSE = GetObject("LDAP://RootDSE")
StrNamingContext = oRootDSE.Get("defaultNamingContext")
Set oRootDSE = Nothing
Set objOU = GetObject("LDAP://OU=test,OU=Users1," & strnamingcontext)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arruserList = Split(strNextLine , ",")
lname = arruserList(0)
fname = arruserList(1)
userid = arruserList(2)
password = arruserList(3)
Set objUser = objOU.Create("User", "cn=" & userid)
objUser.Put "sAMAccountName", userid
objUser.SetInfo
Set objUser = GetObject _
("LDAP://cn=" & userid & ",ou=test,OU=USERS1," & strnamingcontext)
objUser.AccountDisabled = FALSE
objUser.SetPassword password
objUser.Put "givenName", fname
objUser.Put "sn", lname
objUser.Put "displayName", lname & ", " & fname
objUser.SetInfo
Loop
Msgbox "Processing complete"

Hope it helps

Steve Regards
Steve Friday
 
Just one thought,

the following lines
Set oRootDSE = GetObject("LDAP://RootDSE")
StrNamingContext = oRootDSE.Get("defaultNamingContext")
Set oRootDSE = Nothing

These get the name of the AD It will return the DC portion.

Regards
Steve Friday
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top