Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: ADSI: Getting a full list of users from a w2k domain

by OzzyOsbourne (Chaplain)
on Sep 10, 2002 at 18:21 UTC ( [id://196775]=note: print w/replies, xml ) Need Help??


in reply to Re: ADSI: Getting a full list of users from a w2k domain
in thread ADSI: Getting a full list of users from a w2k domain

thanks for the reply! This flexed my brain a bit, and led me to other avenues, but still didn't work. I still get 1000 lines.

You know that feeling when you work on one line for days? That's how I feel. Does pounding one's head against something solid prodce better code? If so, I should be a master by now.

Update

I fiddled with the lines until I got it to work. I'm still not sure if it's the ordering of the commands, the double quotes around Page Size, or some combination thereof. the Full Orphan Script will be posted to the Code catacombs. Thanks to cacharbe for all of his suggestions

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"); # Create the ADO Command my $ADSPath = "LDAP://OU=group,DC=subdomain,DC=domain,DC=com"; my $ADOCmd=Win32::OLE->new("ADODB.Command"); $ADOCmd->{ActiveConnection}=$ADO; $ADOCmd->{CommandText}="<$ADSPath>;(objectClass=User);samAccountNa +me,HomeDirectory;SubTree";#new $ADOCmd->Properties->{"Page Size"}=10000; #Execute the Command my $users=$ADOCmd->Execute; #Extract the Info (AccountName, HomeDirectory) from the returned o +bject until ($users->EOF){ my $homeDir=lc($users->Fields(1)->{Value}); my $account=lc($users->Fields(0)->{Value}); print OUT "$account\t$homeDir\n"; $users->MoveNext; } $users->Close; $ADO->Close; print "Wrote Accounts\n"; }

-OzzyOsbourne

Replies are listed 'Best First'.
Re: Re: Re: ADSI: Getting a full list of users from a w2k domain
by cacharbe (Curate) on Sep 10, 2002 at 18:41 UTC
    I know exactly how you feel.

    Check the settings on you AD Server, as per this and this, and note the caveats and limitations on the latter page regarding max number of entries in a secondary user group, and the MAX size of MaxPageSize.

    Short of it: Looks like you can set MaxPageSize in AD as well, but the MAX MaxPageSize / request is 1000...Looks like you're SOL (another microsoft link here that supports the claim).

    C-.

    ---
    Flex the Geek

      But it can be done in VBScript with almost identical code. The offending line that I can't translate from VBScript is objADOCmd.Properties("Page Size")=10000. So it must be possible. I'm missing something. I have to be.

      -OzzyOsbourne

        Well, when you execute a command object, you get back a recordset object. Why not prep the RS object ahead of time, and use the command and connection objects after your leg work is done, like so:
        use Win32::OLE 'in'; my $ADO = Win32::OLE->new("ADODB.Connection"); $ADO->{Provider} = "ADsDSOObject"; $ADO->Open("ADSI Provider"); my $ADOCmd=Win32::OLE->new("ADODB.Command"); $ADOCmd->{ActiveConnection}=$ADO;#new $ADOCmd->{CommandText}="<$ADSPath>;(objectClass=User);samAccountNam +e,HomeDirectory;SubTree"; my $ADOrs = Win32::OLE->new("ADODB.RecordSet"); $ADOrs->PageSize->{Value}=10000; $ADOrs->Open({Source=>$ADOCmd, ActiveConnection=>$ADO,}) until ($ADOrs->EOF){ my $homeDir=lc($ADOrs->Fields(1)->{Value}); if ($homeDir=~/^\\\\mf/){ my $account=lc($ADOrs->Fields(0)->{Value}); print OUT "$account\t$homeDir\n"; } $ADOrs->MoveNext; } $ADOrs->Close; $ADO->Close; print "Wrote Accounts\n";
        My thought is that in VB, you are lucky enough to be able to set the PageSize Property ahead of time, and on execution, the properties are applied when the object is returned. I've come to this (perhaps erroneous) conclusion because if you create the command object and then enumerate through the Command Properties before execution, you get back an empty set.

        C-.

        ---
        Flex the Geek

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://196775]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2024-04-16 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found