Matchete has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get the DN for a given username in a csv file using the Win32::ad::user module in Perl, but I can't seem to get the syntax right. Here's my code... (domain name has been replaced)

#!/usr/bin/perl #use strict; use warnings; use Win32::AD::User; use Text::CSV; use Net::LDAP; my $file = "Users.csv"; my $csv = Text::CSV-&gt;new(); open (CSV, "&lt;", $file) or die $!; while (<CSV>) { if ($csv-&gt;parse($_)) { my @username = $csv->fields(); my $user = $username[0]; my $adstring = join('', $user, ',user",',$user, '"'); my $acdiruser=Win32::AD::User-&gt;new('WinNT://my.domain.EDU/ ',$u +ser); $acdiruser-&gt;get_info(); print join ("\n", $acdiruser-&gt;get_property( dn )); } } close CSV;

Any ideas?

Thanks!!!

Replies are listed 'Best First'.
Re: Win32::AD::User - can't seem to figure out how to retrieve a DN
by wwe (Friar) on May 18, 2012 at 08:09 UTC
    you pass a wrong string to the Win32::AD::User. There is no need in additional ',user' strings you add here:
    my $adstring = join('', $user, ',user",',$user, '"');
    It works in my environment with:
    my $acdiruser=Win32::AD::User->new('WinNT://dnsdomain.com/',$user);
    and
    my $acdiruser=Win32::AD::User->new('WinNT://NTDOMAIN/',$user);
    you can print out all available properties using $acdiruser->print_me(); I'm not sure if it depends on my limited rights the property _LDAPAdsPath: which I expect to contain the DN attribute is empty for me :-(