| Store | Cart

Listing computers from a specific OU

From: A F <perl...@yahoo.com>
Tue, 28 Jun 2011 21:48:03 -0700 (PDT)
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

Recent Messages in this Thread
Gomes, Rich Apr 26, 2011 05:52 pm
Steven Manross Apr 26, 2011 07:51 pm
A F Jun 29, 2011 04:48 am
Steven Manross Jun 29, 2011 06:05 am
A F Jul 01, 2011 03:05 am
Deans, Glenn (IT Solutions US) Jul 01, 2011 01:24 pm
Messages in this thread