A trivial addition to the ISG::Win32::ActiveDirectory module of Tobias Oetiker & David Schweikert at the Swiss Polytechnic Institute. It adds a method to return an object handle instead of a distinguished name, for those times when you're going to work with everything in an OU, you don't care what the name is, and you don't want to bind to them twice.

Not tested with the 23 March 2007 update, but should work anyway.

sub AD_enumerate_O ($$) { my $dn = shift; my $type = shift; $dn =~ s|^(LDAP://)?|LDAP://|; disable_ole_warnings; my $ou_hand = Win32::OLE->GetObject("$dn"); # this does not seem to work # $ou_hand->{Filter} = [ $type ]; enable_ole_warnings; if (not $ou_hand) { carp "WARNING: ".Win32::OLE::LastError."\n"; return undef; } my @list; foreach my $hand ( in $ou_hand ){ # other interesting properties are: # http://msdn.microsoft.com/library/en-us/netdir/adsi/iads.asp # also works for the 'other' properties of the entry next unless $hand->{Class} eq $type; #simpler than filter push @list, $hand; }; return [ @list ]; }

Replies are listed 'Best First'.
Re: Active Directory Object Handles
by jdporter (Paladin) on May 31, 2007 at 14:19 UTC
    my @list; foreach my $hand ( in $ou_hand ) { next unless $hand->{Class} eq $type; push @list, $hand; }; return [ @list ];
    would be better (i.e. more perlishly) written as
    [ grep { $_->{Class} eq $type } in $ou_hand ]
      You're right. But when I said "trivial addition", though, I wasn't kidding. I just deleted the part of their AD_enumerate method that got the name, and returned the handle.:-)