Populating LDAP with test users

Posted on 2006-04-05
Last Modified: 2008-03-10
 i am looking for a code, where in i can populate say 100 users in a particular ou in ldap (iPlanet). I would be glad if the experts could help in figuring out a way for this
Question by:itsme_asif
    LVL 84

    Expert Comment


    Author Comment

    Thanks a lot, can i have some more examples, i am kinda rusty with perl
    LVL 6

    Expert Comment

    What kind of directory are you talking about? x.500? Active Directory? NDS?

    Here is an example for active directory.

    use Win32::OLE 'in';

    my $server = "MyServerName";

    my $obj = Win32::OLE->GetObject("LDAP://$server/OU=iPlanet,DC=Domain,DC=Com");

    open(USERS, "users.txt") || die "Could not find users.txt file\n";
    @users = <USERS>;


    # users.txt should be a file formated like
    # Charles,Dickens,cdickens,scrooge
    # Emily,Walworth,ewalworth,cookies
    # etc...etc...

    foreach my $user(@users) {

        my($firstname,$lastname,$userid,$password) = split("\,",$user);
          my $objUser   = $obj->Create("user", "cn=$firstname $lastname");
          $objUser->Put("sAMAccountName", "$userid");  
          $objUser->Put("userPrincipalName", "$userid\");
          $objUser->Put("givenName", "$firstname");  
          $objUser->Put("sn", "$lastname");          
          $objUser->Put("displayName", "$firstname $lastname");
          $objUser->{AccountDisabled} = FALSE;
          if(Win32::OLE::LastError()) {
              print Win32::OLE::LastError,"\n\n";
          else {
              print "Created $firstname $lastname : $userid\n";

    print "Done\n";

    Author Comment

    I am looking for LDAP, i am using a iPlanet Directory Server 5.1 from Sun which is a LDAP. It would be really helpfull if you could give me a similar example as in AD.
    LVL 6

    Expert Comment

    I see. I am going to look into this a little more. I would use the perLdap module for this. I don't have enough information on iPlanet but I might find what I need to give you something to start with.


    Author Comment

    Thanks a lot
    LVL 51

    Expert Comment

    what's wrong with
      man Net::LDAP
    as suggested by ozo?
    Net::LDAP works perfect with iPlanet.

    Author Comment

    do i have to download the package or if i add Net::LDAP in my code is enough? for example
    use Net::LDAP;
     $ldap = Net::LDAP->new( '' ) or die "$@";
     $mesg = $ldap->bind ;    # an anonymous bind
     $mesg = $ldap->search( # perform a search
                            base   => "c=US",
                            filter => "(&(sn=Barr) (o=Texas Instruments))"
     $mesg->code && die $mesg->error;
     foreach $entry ($mesg->entries) { $entry->dump; }
     $mesg = $ldap->unbind;   # take down session
     $ldap = Net::LDAP->new( '' );
     # bind to a directory with dn and password
     $mesg = $ldap->bind( 'cn=root, o=University of Michigan, c=us',
                          password => 'secret'
     $result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan, c=US',
                           attr => [
                             'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
                             'sn'   => 'Jensen',
                             'mail' => '',
                             'objectclass' => ['top', 'person',
                                               'inetOrgPerson' ],
     $result->code && warn "failed to add entry: ", $result->error ;
     $mesg = $ldap->unbind;  # take down session

    would the above code work, with no modification (when the bind instructions are changes according to my directory)
    LVL 51

    Accepted Solution

    > do i have to download the package
    you have to install Net::LDAP module

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now