> -----Original Message----- > From: [email protected] [mailto:perl- > [email protected]] On Behalf Of Gomes, Rich > Sent: Thursday, April 21, 2011 11:18 AM > To: [email protected] > Subject: AD Page Size help > > I know this has been talked about a lot but I cannot seem to get my > script to work. > I am trying to not hit the LDAP search limit but cannot seem to get the > PageSize line correct > > > Any thoughts?
I never tried to do paged queries via Win32::OLE, instead I used the
following modules:
use Net::LDAP;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED );
calls like this worked for me:
my( $ldap ) = Net::LDAP->new( $ldapHost ) or die "$@";
.
.
.
$mesg = $ldap->bind( $ID, password => $PW );
$page = Net::LDAP::Control::Paged->new( size => PAGE_SIZE );
@args = (
Sizelimit => LDAP_SIZELIMIT,
scope => LDAP_SCOPE,
base => &makeBaseDN,
filter => LDAP_FILTER,
attrs => [ LDAP_ATTR ],
control => [ $page ],
);
while( 1 ) {
$mesg = $ldap->search( @args );
last if ( $mesg->code && $mesg->code != 4 );
foreach my $entry ( $mesg->entries ) {
my $dn = $entry->dn();
foreach my $attr ( $entry->attributes ) {
my $value = $entry->get_value( $attr );
# do something with $value
}
}
$objCount += $mesg->count;
last unless my( $resp ) = $mesg->control( LDAP_CONTROL_PAGED );
last unless $cookie = $resp->cookie;
$page->cookie( $cookie );
}
if ( $cookie ) {
printf $tee "INFO: query interrupted: %s: %s!\n", $mesg->code,
$mesg->error;
$page->cookie( $cookie );
$page->size( 0 );
$ldap->search( @args );
foreach my $entry ( $mesg->entries ) {
my $dn = $entry->dn();
foreach my $attr ( $entry->attributes ) {
my $value = $entry->get_value( $attr );
# do something with $value
}
}
$objCount += $mesg->count;
}
$mesg = $ldap->unbind; # take down session
> _______________________________________________________________________
> ______
>
> my $strDomainDN = "DC=mydomain,DC=com";
> use Win32::OLE qw(in);
>
>
> $Win32::OLE::Warn = 3;
> my $strBase = "<LDAP://" . $strDomainDN . ">;";
>
>
> my $strFilter = "(&(objectclass=user)(objectcategory=person));";
> my $strAttrs = "name;";
> my $strAttrs = "distinguishedName;";
> my $strScope = "subtree";
>
> my $objConn = Win32::OLE->CreateObject("ADODB.Connection");
> $objConn->{Provider} = "ADsDSOObject";
> $objConn->Open;
>
> $objConn->{Properties}->{"Page Size"} = 100;
>
> my $objRS = $objConn->Execute($strBase . $strFilter . $strAttrs .
> $strScope);
> $objRS->MoveFirst;
> while (not $objRS->EOF) {
> print $objRS->Fields(0)->Value,"\n";
> $objRS->MoveNext;
> }
>
> _______________________________________________________________________
> ________
>
>
>
> _______________________________________________
> Perl-Win32-Admin mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Perl-Win32-Admin mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
