Use the blue Nav bar above to access the main index pages!

Search Active Directory from Perl Using ADO

This is how to use ADO from Perl to search Active Directory. Once you learn how to search, you'll find that you'll use this technique over and over again in your scripts.

This example finds all users in the forest whose first name is Reginald.  To learn more about searching Active Directory, please see my more recent article Active Directory Enumeration and Search

use Win32::OLE;
$dse=Win32::OLE->GetObject("LDAP://RootDSE");
$root=$dse->Get("RootDomainNamingContext");
$adpath="GC://$root";
$base="<".$adpath.">";
$connection = Win32::OLE->new("ADODB.Connection");
$connection->{Provider} = "ADsDSOObject";
$connection->Open("ADSI Provider");
$command=Win32::OLE->new("ADODB.Command");
$command->{ActiveConnection}=$connection;
$command->{Properties}->{'Page Size'}=1000;
$rs = Win32::OLE->new("ADODB.RecordSet");
$command->{CommandText}="$base;(&(objectCategory=User)(givenName=Reginald));displayName;subtree";
$rs=$command->Execute;
until ($rs->EOF){
 $displayName=$rs->Fields(0)->{Value};
 print "$displayName\n";
 $rs->MoveNext;
}

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...