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

Creating multiple users in the Active directory with LDAP

Status
Not open for further replies.

vijmat

IS-IT--Management
Jun 19, 2001
100
US
Hi
I have to create around 200 user accounts in the Windows 2000 Active directory domain. Creating it one by one would be a painful process. I know there is a way to do this using LDAP programming, although I do not recall how.

It would be great if someone can help me out in this.

Thanks
Viju
 
What exactly do you need mean by registering manually?
so you want to register from SQL to Membership??
 
you can use idifde.exe available with the windows2000 server it is installed automatically and can be accessed in the cmd window. the full help of idifde.exe will be availbale after just typing the idifde at the command prompt.
 
I recommend a scripting tool called kixtart. I've written scripts that allow me to create 2000 student accounts on a W2K domain with everything needed (user folders, random 5 character passwords, etc.) in about 20 minutes.
 
Care to share those scripts. I would really appreciate the help.
 
Do you have the information in a csv or other type of file? If so you can easily parse that into ldif format using your favorite text parsing language and use either ldifde or ldapmodify to add the information to the server. Additionally you could use perl-ldap or other means from other languages to automate the additions on the fly ... though you may not want to try that out of the gate ... you do have tons of options though ...
 
Sorry for the long wait: here are the kix scripts I uise to create accounts:
It's sectioned off so that it should be easy to follow

Code:
? "Create / Modify Student Accounts? (y/n)"
GET $t
IF $t <> &quot;y&quot; quit ENDIF

call @SCRIPTDIR+&quot;\functions.udf&quot;

;===== Open Database And Prepare Table
IF EXIST (&quot;c:\scripts\userlist.mdb&quot;) = 1
del &quot;c:\scripts\userlist.mdb&quot;
ENDIF
copy &quot;c:\scripts\blank.mdb&quot; &quot;c:\scripts\userlist.mdb&quot;
$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=c:\scripts\userlist.mdb')
$SQL = &quot;CREATE TABLE PRINTOUT (name char(50), username char(50), password char(50), schoolname char(50), description char(50))&quot;
$NULL= DBCommand($objConn,$SQL)

$ShareSrvObj = GetObject(&quot;WinNT://NT_ADMIN/LANMANSERVER&quot;)

;====== Get User Info From Text File
$NULL=Open(1,&quot;c:\scripts\users.txt&quot;)
$result=ReadLine(1)
WHILE $result<>&quot;&quot;
$uarray=SPLIT($result,&quot;#&quot;)
$username=$uarray[0]
$firstname=$uarray[1]
$lastname=$uarray[2]
$description=&quot;Class of &quot;+$uarray[3]
$group=$uarray[4]
$fullname=$lastname+&quot;, &quot;+$firstname
If $group = &quot;Students&quot;
    $schoolname = &quot;High School&quot;
ENDIF
If $group = &quot;msstudents&quot;
    $schoolname = &quot;Middle School&quot;
ENDIF
If $group = &quot;fwstudents&quot;
    $schoolname = &quot;Fountain Woods&quot;
ENDIF
;====== End Get User Info From Text File

;====== Generate Password
dim $parray[4]
SRND(@MSECS*@MSECS)
For $i=0 to 4
$parray[$i]=Chr(97+Rnd(122-97))
Next
$password=JOIN($parray,&quot;&quot;)
;====== End Generate Password


;====== Check If User Exists
$usercheck = getobject(&quot;WinNT://BURLINGTON/$username,user&quot;)
if $usercheck=1
    $userexists=1
    $usercheck=0
    else
        $userexists=0
endif

;====== Create New User Account
IF $userexists=0
    $objOU = GetObject(&quot;LDAP://ou=Students,ou=Domain Users,dc=burlington,dc=org&quot;)
    $objUser = $objOU.Create(&quot;User&quot;,&quot;cn=$username&quot;)
    $objUser.Put (&quot;samAccountname&quot;, &quot;$username&quot;)
    $objUser.SetInfo
    $objOU = &quot;&quot;
    $objUser = &quot;&quot;
ENDIF

$objUser = GetObject(&quot;LDAP://cn=$username,ou=Students,ou=Domain Users,dc=burlington,dc=org&quot;)
$objUser.AccountDisabled = FALSE
$objUser.IsAccountLocked = FALSE
$objUser.PasswordRequired = FALSE
$objUser.givenName = &quot;$firstname&quot;
$objUser.sn = &quot;$lastname&quot;
$objUser.displayName = &quot;$fullname&quot;
$objUser.description = &quot;$description&quot;
$objUser.scriptPath = &quot;logon.bat&quot;
$objUser.SetPassword($password)
$UserFlags = $objUser.Get(&quot;userAccountControl&quot;)
$UF_DONT_EXPIRE_PASSWD = 65536
$NewUserFlags = $UserFlags | $UF_DONT_EXPIRE_PASSWD
$objUser.Put (&quot;userAccountControl&quot;, $NewUserFlags)
$objUser.SetInfo
$objUser = &quot;&quot;

shell '%comspec% /c net user $username /passwordchg:no /domain'
shell '%comspec% /c net group $group $username /add /domain'
;====== End Create New User Account

;====== User's Network Folders
IF NOT EXIST(&quot;\\nt_admin\d$\users\$username&quot;)
    md &quot;\\nt_admin\d$\users\$username&quot;
ENDIF

$NewShareObj = $ShareSrvObj.Create(&quot;fileshare&quot;, &quot;$username&quot;+&quot;$&quot;)
$NewShareObj.Path = &quot;D:\users\$username&quot;
$NewShareObj.SetInfo
$NewShareObj=&quot;&quot;
;====== End User's Network Folders

;====== Send User Info To Database For Mailers

;==First replace any ' with `
IF INSTR($fullname,&quot;'&quot;) <>0
$fullarray=SPLIT($fullname,&quot;'&quot;)
$fullname=JOIN($fullarray,&quot;`&quot;)
ENDIF
;==End Replace

$SQL = &quot;INSERT INTO PRINTOUT (name,username,password,schoolname,description) VALUES ('$fullname','$username','$password','$schoolname','$description')&quot;
$NULL= DBCommand($objConn,$SQL)
;====== End Send User Info To Database for Mailers

$result=ReadLine(1)
LOOP
$NULL=Close(1)

;====== Close Database
$NULL=DBConnClose($objConn)
$ShareSrvObj=&quot;&quot;

;====== Open Word And Print Mailers
$word=createobject(&quot;Word.Application&quot;)
$word.Visible = 1
$null=$word.Documents.Open(&quot;c:\scripts\mailer.doc&quot;)
$null=$word.ActiveDocument.MailMerge.Execute
$null=$word.quit(0)
$word=0

;====== Clean Up
sleep 5
del &quot;c:\scripts\userlist.mdb&quot;

;====== Process CACLS
$NULL=Open(2,&quot;c:\scripts\users.txt&quot;)
$result=ReadLine(2)
WHILE $result<>&quot;&quot;
 $uarray=SPLIT($result,&quot;#&quot;)
 $username=$uarray[0]
 SHELL &quot;xcacls \\nt_admin\d$\users\$username /t /c /g $username:c burlington\administrator:f &quot;+Chr(34)+&quot;domain admins&quot;+Chr(34)+&quot;:f system:f staff:r /y&quot;
 $result=ReadLine(2)
LOOP
$NULL=Close(2)
quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top