Henry,
Thanks for this bit of code - I really need something like this to get me started. I made the changes so as to "get my feet wet". Fired up the script and got the following: IO::Socket::INET: Timeout at ldap_test2.pl line 7. Where do I go from here to trouble shoot this problem? Thanks. -----Original Message----- From: henry isham [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 21, 2002 7:55 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Net::LDAP and ADSI question. Hi All, Below is some code I'm currently using, which is mostly borrowed from Net::LDAP documentation, that works pretty well when making simple queries against our local Win2K AD servers. When I try to modify the $result line with something like {my $result = LDAPsearch($ldap,"cn ne someuserID",\@Attrs); }, or {my $result = LDAPsearch($ldap,"cn <> someuserID",\@Attrs); }, I get no results. It seems that it doesn't like the 'ne' or '<>' operators. As far as I can see, if I want to do a more refined search, I have to make a more general search string and then do more pattern matching before I output the data to file or console. I can see this as being inefficient. So, here's my question: is it possible to generate a more specific $searchString? Can LDAP handle those kind of requests? If so, can someone point me to some docs that do that, or just give me a quick example? Another question, is this the best way to do it, or should I be looking into a Win32::OLE->... solution? I'm using LDAP because I couldn't find any perl docs for Win32::OLE->... and ADSI being used together. Any help would be greatly appreciated... -Henry. use Net::LDAP qw(:all); # use for all code use Net::LDAP::Util qw(ldap_error_name ldap_error_text) ; # use for Error handling $ldap = Net::LDAP->new("my.domain.net") or die "$@"; $mesg = $ldap->bind( version => 3 ); # use for searches $mesg = $ldap->bind("me\@my.domain.net", password => "mypass", version => 3 ); sub LDAPsearch { my ($ldap,$searchString,$attrs,$base) = @_ ; # Set default base.... if (!$base ) { $base = "dc=my, dc=domain, dc=net"; } # Set default attributes... if (!$attrs ) { $attrs = ['sn=','*' ]; } my $result = $ldap->search ( base => "$base", scope => "sub", filter => "$searchString", attrs => $attrs ); } my @Attrs = ("cn","displayname","lastlogon"); # request all available attributes to be returned.(i.e."lastlogon","mail") my $result = LDAPsearch($ldap,"cn=someuserID",\@Attrs); #------------ # # Accessing the data as if in a structure # i.e. Using the "as_struct" method # my $href = $result->as_struct; # get an array of the DN names my @arrayOfDNs = keys %$href ; # use DN hashes # process each DN using it as a key foreach (@arrayOfDNs) { print $_,"\n"; my $valref = $$href{$_}; # get an array of the attribute names # passed for this one DN. my @arrayOfAttrs = sort keys %$valref; #use Attr hashes my $attrName; foreach $attrName (@arrayOfAttrs) { # skip any binary data: yuck! next if ( $attrName =~ /;binary$/ ); # get the attribute value (pointer) using the # attribute name as the hash my $attrVal = @$valref{$attrName} ; print "\t $attrName: @$attrVal \n"; } print "#-------------------------------\n"; # End of that DN } # # end of as_struct method = Z)KɚXXh吧e,zົ%lz婻r†y+Z(:.ᯞ˛ mmඟ+-䱱癯bjoj)fj›˛ _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs