Simple Search (Perl)
This code can be found in
Chapter 22 of Active Directory, 3rd Edition
Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.
Find out how to download all of the Perl code from this site.
# From the book "Active Directory, Third Edition"
# ISBN: 0-596-10173-2
use Win32::OLE;
use constant vbCrLf => "\r\n";
use strict;
use constant adStateOpen => 1;
my $objConn;
# ADO Connection object
my $objRS;
# ADO Recordset object
$objConn = Win32::OLE->new('ADODB.Connection');
$objConn->{Provider} = 'ADSDSOObject';
$objConn->Open('', 'CN=Administrator,CN=Users,dc=mycorp,dc=com', 'mypass');
if ($objConn->State == adStateOpen) {
print "Authentication Successful!\n";
}
else {
print "Authentication Failed.\n";
exit (1);
}
$objRS = $objConn->Execute('<LDAP://dc=mycorp,dc=com>;(&(objectCategory=person)' . '(objectClass=user));Name,ADsPath;SubTree');
while (!$objRS->EOF) {
print $objRS->Fields->Item('Name')->Value . vbCrLf . $objRS->Fields->Item('ADsPath')->Value, "\n";
$objRS->MoveNext();
}
$objRS = undef;
$objConn->Close();
|
This code has been viewed 1363 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|