Hi All,
I have this code from Steven that I've modified to get the number of all
computer in a specific ou ( OU=History,OU=Disabled Computers) but I am getting
0.
This is the filter I am using
(&(objectclass=Computer)(Distinguishedname=*Disabled*)). There are about 500
computers in that OU.
How can I get a record count from that OU?
use Win32::OLE;
my $RootDSE = Win32::OLE->GetObject("LDAP://RootDSE");
$dc = $RootDSE->Get("DnsHostName");
print "$dc\n";
query_ldap("<LDAP://" . $dc .
">;(&(objectclass=Computer)(Distinguishedname=*Disabled*)
);displayname,distinguishedname;subtree",$objects);
print "recordcount = ".$objects->{RecordCount}."\n";
sub query_ldap {
my $ldap_query = $_[0];
my $error_num;
my $error_name;
my $RS;
my $Conn = Win32::OLE->new("ADODB.Connection");
if (Win32::OLE->LastError() != 0) {
print "Failed creating ADODB.Connection object
(".Win32::OLE->LastError().")\n -> $ldap_query\n";
return 0;
}
$Conn->{'Provider'} = "ADsDSOObject";
if (Win32::OLE->LastError() != 0) {
print "Failed setting ADODB.Command Provider
(".Win32::OLE->LastError().")\n -> $ldap_query\n";
return 0;
}
#$Conn->{Open} = "Perl Active Directory Query";
$Conn->{Open} = "Active Directory Provider";
my $Cmd = Win32::OLE->new("ADODB.Command");
$Cmd->{ActiveConnection} = $Conn;
if (Win32::OLE->LastError() != 0) {
print "Failed creating ADODB.Command object
(".Win32::OLE->LastError().")\n -> $ldap_query\n";
return 0;
}
$Cmd->{CommandText} = $ldap_query;
$Cmd->{ActiveConnection} = $Conn;
$Cmd->{Properties}->{"Page Size"} = 500;
$RS = $Cmd->Execute();
if (Win32::OLE->LastError() != 0) {
print "Failed Executing ADODB Command object
(".Win32::OLE->LastError().")\nExecuting ADODB Command -> $ldap_query\n";
return 0;
} else {
$_[1] = $RS;
return 1;
}
}
_______________________________________________
Perl-Win32-Admin mailing list
Perl...@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs