Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-25 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found