Hi Randy,

there are no bulk operation commands in ldap. You'll have to run for each user 
one ldap query. In the query you've to include the attributes which hold the 
desired user information.

If you already have the fully qualified CN you also might use the adsi 
interface instead of the ldap interface.

Regards,
Uri



##############################################################################
# CHANGE DISPLAY NAME
##############################################################################
# AUTHOR:
# DATE:
##############################################################################
#
# 04-09-27 Creation
#
##############################################################################
use strict;
use Net::LDAP;
use Win32API::Net qw(GetDCName);

# LDAP ACCESS DATA
my $user   = '[EMAIL PROTECTED]';
my $pwd    = 'PASSWORD';
my $dc     = 'YOURDOMAIN';
my $domain = lc $ENV{USERDOMAIN};

# GET NAMING CONTEXT
my $namingContext = getNamingContext($domain);

# SEARCH PARAMETERS
my $base   = $namingContext;
my $scope  = "subtree";
my $attrs  = qw (displayName distinguishedName userPrincipalName 
extensionAttribute11 extensionAttribute12);
# my $filter = 
"(&(objectclass=user)(objectcategory=user)(givenName=Henry)(sn=Miller))";

# USER LIST
my $userList = 'c:/data/allUsers.txt';
my @userList = open(USERLIST, "<$userList");

# CONNECT
my $ldap = Net::LDAP->new($dc) or die "Connection failed!", $@;

# BIND TO LDAP USER
my $rc = $ldap->bind( $user, password => $pwd);
die $rc->error if $rc->code;


# SEARCH LDAP FOR EACH USER
for my $userID (@userList) {
   my $filter = "(&(objectclass=user)(objectcategory=user)(cn=$userID))";
   my $search = $ldap->search (base => $base, scope => $scope, filter => 
$filter, attrs => $attrs);
   if ($search->code) {
      print $search->error;
      next;
   }
   processResults($search);
}


# UNBIND
$ldap->unbind;


exit;



##############################################################################
# PROCESS RESULTS
##############################################################################
sub processResults {
##############################################################################
   my ($search) = @_;

   print 
"\n********************************************************************\n";
   print "Displaying certain Results...\n";
   print 
"********************************************************************\n";


   # DISPLAY CERTAIN SEARCH RESULTS
   for my $entry ($search->entries) {

      my $displayName = $entry->get_value('displayName');
      print "displayName: $displayName\n";

      my $distinguishedName = $entry->get_value('distinguishedName');
      print "distinguishedName: $distinguishedName\n";

      my $extensionAttribute11 = $entry->get_value('extensionAttribute11');
      print "extensionAttribute11: $extensionAttribute11\n";

      my $extensionAttribute12 = $entry->get_value('extensionAttribute12');
      print "extensionAttribute12: $extensionAttribute12\n";

   }
}



##############################################################################
# GET DEFAULT NAMING CONTEXT
##############################################################################
sub getNamingContext {

   my ($domain) = @_;

   my ($ldap, $rootdse, $defaultNamingContext);

   $ldap                 = Net::LDAP->new($domain) or die $@;
   $rootdse              = $ldap->root_dse(attrs => ['defaultNamingContext']);
   $defaultNamingContext = $rootdse->get_value('defaultNamingContext');

   return $defaultNamingContext;

}



use strict;
use Win32;
use Win32::OLE;


# DOMAIN CONTROLLER
my $dc='YOUR-DC';

# USER LIST
my $userList = 'c:/data/allUsers.txt';
my @userList = open(USERLIST, "<$userList");


for my $userID (@userList) {
   processUserID($userID);
}

exit;



# -------------------------------------------------------------
sub processUserID {

   my ($userID) = @_;

   print "\n\nDisplaying User Info for $userID...\n";

   # ADSI PATH FOR SPECIFIC USER
   $adspath = 
"LDAP://CN=$userID,OU=Staff,OU=OrgUsers,OU=DepartementXYZ,DC=YOURCOMPANY,DC=com";;

   # CREATE / BIND OBJECT FOR SPECIFIC USER
   $user = Win32::OLE->GetObject($adspath) or {
      die "Bind failed: $adspath\n";
      return;
   }
   

   # GET INFO
   $user->GetInfo();

   # READ SINGLE ATTRIBUTES
   my $firstname            = $user->Get("givenName");
   my $initials             = $user->Get("initials");
   my $lastname             = $user->Get("sn");
   my $displayname          = $user->Get("displayName");
   my $description          = $user->Get("description");
   my $office               = $user->Get("physicalDeliveryOfficeName");
   my $telephonenumber      = $user->Get("telephoneNumber");
   my $email                = $user->Get("mail");
   my $webpage              = $user->Get("wWWHomePage");
   my $homeMDB              = $user->Get("homeMDB");
   my $msExchHomeServerName = $user->Get("msExchHomeServerName");
   my $legacyExchangeDN     = $user->Get("legacyExchangeDN");
   my $extensionAttribute2  = $user->Get("extensionAttribute2");

   # JOIN MULTI VALUE ENTRY
   my $objectClass          = join ", ", @{$user->Get("objectClass")};

   # PRINT
   print "First name:                $firstname\n";
   print "Initials:                  $initials\n";
   print "Last name:                 $lastname\n";
   print "Display name:              $displayname\n";
   print "Description:               $description\n";
   print "Office:                    $office\n";
   print "Telephone number:          $telephonenumber\n";
   print "E-mail:                    $email\n";
   print "Web page:                  $webpage\n";
   print "Mail Server:               $homeMDB\n";
   print "Mail Server:               $msExchHomeServerName\n";
   print "Exchange Receipient:       $legacyExchangeDN\n";
   print "extensionAttribute2:       $extensionAttribute2\n";
   print "objectClass:               $objectClass\n";
   print "Current MDB:               ". $user->HomeMDB();
}









-----Original Message-----
From: randy.m.briggin [mailto:[EMAIL PROTECTED] 
Sent: Donnerstag, 24. März 2005 18:01
To: [EMAIL PROTECTED]
Subject: LDAP Search Question

Hello Mr. Barr

 

Thank you very much for your work and development on the net::ldap package for 
Perl. I am sorry to bother you but, I can't seen to get around this problem I 
have searched exhaustively looking for an example or text describing how to 
accomplish my task. Would you please point me in the correct direction to 
answer my question.  Through your documentation I was able to complete part of 
my objective which is to search our active directory and get specific 
information about a specific user. The end result is I need to pass a list of 
userID's to my program and get information about them and then put that 
information into a text file. To debug and test my program I hard coded all the 
variable into my program and everything worked great however when I try to 
input any variable during the execution of my program it just hangs and then I 
get a I/O timeout error. I can seem to find any documentation on how to 
interject  a variable into the program from either from the command line or a 
text file read into the program. I included my code in this email if you would 
look at it to see if I am using the wrong functions to accomplish what I am 
trying to do.  Any help you will give me will be greatly appreciated thank you 
in advance for your help.

 

The test code I added after I was able to get the program running is between 
the "#" . What I was trying to do was two things make the program usable by 
someone other than myself that is why I added the (2) lines asking for your 
ZID(loginID) and password and the 3rd line asking for ZID to search on. The 
original intent was to pass only ZID's from a text file to the program  to get 
information about the users.

 

use strict;

use Net::LDAP;

 

##################################################

system("clear");

print("Enter your ZID:   ");

my $sMyZid =  <STDIN>;

chop $sMyZid;

print("Enter your northamerica PW:   ");

my $sPw = <STDIN>;

chop $sPw;

system("clear");

print("Enter ZID to search for:   ");

my $sZid = <STDIN>;

chop $sZid;

##################################################

 

# Connection and binding parameters

my $dc     = 'my domain';

my $user   = 'my loginname';

my $passwd = 'my password';

my $port = '3268';

my $host = 'my hostname';

 

 

# Search parameters

my $base   = "dc=myCompany,dc=net";

my $scope  = "subtree";

my $filter =
"(&(objectclass=user)(objectcategory=user)(sAMAccountName=sZid))";

my @attrs = qw(cn mail telephoneNumber physicalDeliveryOfficeName l co);

 

my $ldap = Net::LDAP->new($dc, hostname => $host, port => $port) or die $@;

 

my $rc = $ldap->bind( $user, password => $passwd,);

die $rc->error if $rc->code;

 

#----------------#

# Callout A

#----------------#

my $search = $ldap->search (

                            base   => $base,

                            scope  => $scope,

                            filter => $filter,

                            attrs  => [EMAIL PROTECTED]

                           );

die $search->error if $search->code;

 

#----------------#

# Callout B

#----------------#

foreach my $entry ($search->entries) {

   $entry->dump;

}

 

$ldap->unbind;

 

 

Thanks Randy

 

Randy Briggin

Information Technology

1441 W. Long Lake Rd.

Troy Michigan, 48098

MC: 480-415-220

Telephone: 248-267-0963

Fax: 248-267-8840

email: [EMAIL PROTECTED]

 

 

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

  Note: The information contained in this message may be privileged and  
confidential and thus protected from disclosure. If the reader of this  
message is not the intended recipient, or an employee or agent  
responsible for delivering this message to the intended recipient, you  
are hereby notified that any dissemination, distribution or copying of  
this communication is strictly prohibited. If you have received this  
communication in error, please notify us immediately by replying to the  
message and deleting it from your computer. Thank you.

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

Content Security by MailMarshal

Reply via email to