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

Re: Active Directory DC and OU

by idsfa (Vicar)
on Apr 18, 2006 at 21:37 UTC ( #544208=note: print w/ replies, xml ) Need Help??

in reply to Active Directory DC and OU


You can query an active directory's LDAP entries using the perl modules Net::LDAP or Net::LDAP::Express.Example:

use Net::LDAP; $ldap = Net::LDAP->new( '' ) or die "$@"; $mesg = $ldap->bind ; # an anonymous bind $mesg = $ldap->search( # perform a search base => "c=US", filter => "(&(cn=Some Loser))" ); $mesg->code && die $mesg->error; foreach $entry ($mesg->entries) { $entry->dump; } $mesg = $ldap->unbind; # take down session


The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon

Comment on Re: Active Directory DC and OU
Download Code
Replies are listed 'Best First'.
Re^2: Active Directory DC and OU
by strat (Canon) on Apr 19, 2006 at 08:04 UTC

    If you just want to query ActiveDirectory, Net::LDAP is fine. But for writing, AD seems to have a problem with non-ASCII characters because (except within the distinguishedName) utf-8 is not used and Net::LDAP in version3 insists on writing utf-8.

    • either use Encode to iso-8859-1 and use Net::LDAP version2, e.g.
      my $ldap = Net::LDAP->new($hostname, version => 2) or die "Error: can't connect to '$hostname'";
    • or Win32::AD::User which is good for adding and editing users but doesn't support searches
    • or use pure Win32::OLE (that's the way I prefer). Argel postet some very good links below.

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2015-10-10 19:15 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (257 votes), past polls