Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I am trying to return the users and their home directories from a win2k domain to a text file. I can get the first piece of exmple code to work. Unfortunately, ADSI will only return 1000 records.

To get around this limitation, VB examples seem to create a command object, set the Page Size property, and execute it. There are endless VB Examples (of course!), but I'm finding it difficult to find the right syntax in Perl.

When the Non-working code is run, no records are returned whether the Page size property is set or not.

I waded through MS, google, and all the VB people I know (I didn't actually wade through the people, but you understand) and I'm still stuck.

Working Code

use strict; use Win32::OLE 'in'; my $out="accounts.tmp"; open OUT,">$out" or die "Can't open $out for write"; &get_corp_accts(); close OUT; sub get_corp_accts{ # get ADO object, set the provider, open the connection my $ADO = Win32::OLE->new("ADODB.Connection"); $ADO->{Provider} = "ADsDSOObject"; $ADO->Open("ADSI Provider"); my $ADSPath = "LDAP://OU=Users,OU=group,DC=subdomain,DC=domain,DC= +com"; # prepare and then execute the query my $users = $ADO->Execute("<$ADSPath>;(objectClass=User);samAccoun +tName,HomeDirectory;SubTree"); until ($users->EOF){ my $homeDir=lc($users->Fields(1)->{Value}); if ($homeDir=~/^\\\\mf/){ my $account=lc($users->Fields(0)->{Value}); print OUT "$account\t$homeDir\n"; } $users->MoveNext; } $users->Close; $ADO->Close; print "Wrote Accounts\n"; } sub ole_error_check{ if (Win32::OLE->LastError( )){ die Win32::OLE->LastError(); } }

Non Working Code

use strict; use Win32::OLE 'in'; my $out="accounts.tmp"; open OUT,">$out" or die "Can't open $out for write"; &get_corp_accts(); close OUT; sub get_corp_accts{ # get ADO object, set the provider, open the connection my $ADO = Win32::OLE->new("ADODB.Connection"); my $ADOCmd=Win32::OLE->new("ADODB.Command"); #new $ADO->{Provider} = "ADsDSOObject"; $ADO->Open("ADSI Provider"); $ADOCmd->Properties->{'Page Size'}=10000;#new my $ADSPath = "LDAP://OU=Users,OU=group,DC=subdomain,DC=domain,DC= +com"; $ADOCmd->{ActiveConnection}=$ADO;#new $ADOCmd->{CommandText}="<$ADSPath>;(objectClass=User);samAccountNa +me,HomeDirectory;SubTree";#new # prepare and then execute the query my $users=$ADOCmd->Execute; until ($users->EOF){ my $homeDir=lc($users->Fields(1)->{Value}); if ($homeDir=~/^\\\\mf/){ my $account=lc($users->Fields(0)->{Value}); print OUT "$account\t$homeDir\n"; } $users->MoveNext; } $users->Close; $ADO->Close; print "Wrote Accounts\n"; } sub ole_error_check{ if (Win32::OLE->LastError( )){ die Win32::OLE->LastError(); } }

-OzzyOsbourne


In reply to ADSI: Getting a full list of users from a w2k domain by OzzyOsbourne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (4)
    As of 2014-04-21 00:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (489 votes), past polls