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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert users into LDAP

Status
Not open for further replies.

lintow

Programmer
Nov 29, 2004
82
US
I have a file with 30 users and passwords in it. this file can be any format, right now I have it as a text file. Each user has a password with the username.

I want to programmaticaly insert these users into our LDAP.
Is there a way to do this using VBScript?

any help would appreciated
 
yes, here is the base code that you need to accomplish your goal.

Code:
Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com")
Set objUser = objOU.Create("User", "cn=SmithJohn")
objUser.Put "sAMAccountName", "smithjohn"
objUser.SetInfo
objUser.SetPassword "password"
objUser.SetInfo
objUser.AccountDisabled = False
objUser.SetInfo

I hope you find this post helpful.

Regards,

Mark
 
I have a file with all user names and passwords.
file name is. example: users.txt or user.xls

Is there a way to read that file and put all users in the LDAP

This code here seems like its only putting a specified user in the LDAP.

any help would be appreciated
 
open the file using

FSO.OpenTextFile

read the text file

Do While Not tsFile.AtEndOfStream
sLine = tsFile.ReadLine
aArray = Split(sLine, ",")
sUser = aArray(0)
sPassword = aArray(1)
'call a sub something like markdmac has povided
Loop


 
Take a look at my FAQ faq329-4871 that goes over converting scripts like this to be enterprise ready.

I hope you find this post helpful.

Regards,

Mark
 
Are all of the users going into the same OU? If so then you can hard code the binding to the OU and all you need to do is iterate through the user information to handle the creation of the users.

I hope you find this post helpful.

Regards,

Mark
 
Do you have any sample code of that.
I'm very new to this
 
That is what I describe in the FAQ. Did you review that?

You might be interested int eh script I posted int his thread: thread329-1159009

I hope you find this post helpful.

Regards,

Mark
 
I'm having a problem setting the password to each user when inserting them into the LDAP


Const ForReading = 1
Set objShell = WScript.CreateObject ("WScript.Shell")
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set fileObject = objFSO.OpenTextFile("C:\VB\File.txt", ForReading)

Do While Not fileObject.AtEndOfStream
strLine = fileObject.ReadLine

aArray = Split(strLine, ",")

sUser = aArray(0)
sPassword = aArray(1)
sEmail = aArray(2)

WScript.Echo sUser
WScript.Echo sPassword
WScript.Echo sEmail
'Loop

Dim oContainer
Dim oUser
Set oContainer=GetObject("LDAP://OU=Student,DC=MYCSU,DC=ces,DC=edu")
'Create user
Set oUser = oContainer.Create("User","CN=" & sUser)
'Assign values to user attributes
oUser.Put "samAccountName", sUser
oUser.SetPassword sPassword
oUser.Put "givenName", sUser
oUser.Put "sn", sUser
oUser.Put "userPrincipalName", sEmail
oUser.Put "mail", sEmail
oUser.SetPassword sPassword .....I GET ERROR HERE IT SAYS OBJECT NOT FOUND.
oUser.SetInfo
oUser.AccountDisabled = False
oUser.SetInfo
'Clean up
Set oUser = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
'WScript.Quit
Loop



 
Use a setinfo after setting the samAccountName.

Also looks like you are trying to set it twice.
oUser.Put "samAccountName", sUser[red]
oUser.SetPassword sPassword[/red]
oUser.Put "givenName", sUser
oUser.Put "sn", sUser
oUser.Put "userPrincipalName", sEmail
oUser.Put "mail", sEmail[red]
oUser.SetPassword sPassword[/red] .....I GET ERROR HERE IT SAYS OBJECT NOT FOUND.
oUser.SetInfo
oUser.AccountDisabled = False
oUser.SetInfo

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top