Hello,
try the following way, it has worked for a couple of times in the past:
use Win32::OLE;
$Win32::OLE::Warn = 3;
# connect to AD with explicit credentials
my $conn = Win32::OLE->new('ADODB.Connection');
$conn->{Provider} = 'ADsDSObject';
$conn->Properties->{'User ID'} = 'cn=Strat,ou=User,dc=myDomain,dc=tld';
$conn->Properties->{'Password'} = 'secret';
$conn->open('ADSI Provider');
# search configuration
my $searchBase = 'ou=Benutzer,dc=myDomain,dc=tld';
my $searchFilter = '(&(objectClass=user)(sn=F*))';
my $scope = 'SubTree';
my @wantedAttributes = qw( ADsPath cn sn givenName userPrincipalName
objectGuid title telephoneNumber );
# build AD search string
my $searchString = join( ';', "<$searchBase>", $searchFilter,
join(",", @wantedAttributes), $scope );
# create a command/search object
my $adoCmd = Win32::OLE->new('ADODB.Command');
$adoCmd->{ActiveConnection} = $conn;
$adoCmd->{CommandText} = $searchString;
$adoCmd->Properties->{'Page Size'} = 1000;
# fetch resultsets
my $rs = Win32::OLE->new('ADODB.RecordSet');
$rs->Open( { Source => $adoCmd } );
# fetch entries
while( not $rs->EOF ) {
my( %data ) = map {
$wantedAttributes[$_] => $rs->Fields($_)->{Value}
} 0..$#wantedAttributes;
if( exists $data{objectGuid} ) { # objectGuid is octettstring (=binary)
$data->{objectGuid} = unpack( 'H*', $data->{objectGuid} );
} # if
print "$_ => $data{$_}\n" foreach sort keys %data;
$rs->MoveNext; # move cursor to next object
} # while
$conn->Close();
Regards,
Strat
-----Ursprüngliche Nachricht-----
From: Gomes, Rich
Sent: Thursday, April 21, 2011 5:18 PM
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?
_____________________________________________________________________________
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
_______________________________________________
Perl-Win32-Admin mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs