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

I am trying to convert the SamAccountName to the Distinguished name by using "NameTranslate" I see examples for VBS but not perl. I tried looking at the VBS Code and adapting it to perl but I just don't understand it. (It has been a long day). Could you show me some examples.

2006-09-06 Retitled by Corion, as per Monastery guidelines
Original title: 'NameTranslate'

  • Comment on convert the SamAccountName to the Distinguished name by using "NameTranslate"

Replies are listed 'Best First'.
Re: convert the SamAccountName to the Distinguished name by using "NameTranslate"
by ikegami (Patriarch) on Sep 05, 2006 at 20:18 UTC
    Could we see the VBS that achieves what you want?
      I think, he is refering to this page

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
        That's not a VBS, and it relies on external tools. I could convert the batch file to Perl, but it would still rely on the external tool. I don't think that's what the OP wants.

        Update: Looks like I missed the code far down in the IFRAME. I'm not sure if I'm converting from the format you have, but the following should help you.

        use strict; use warnings; use Win32::OLE (); # Constants for the NameTranslate object. use constant ADS_NAME_INITTYPE_GC => 3; use constant ADS_NAME_TYPE_1779 => 1; use constant ADS_NAME_TYPE_NT4 => 3; # Specify the Display Name of the user. my $nt_name = $ENV{USERDOMAIN} . '\\' . $ENV{USER}; # Use the NameTranslate object to convert the Display Name # of the user to the Distinguished Name. my $name_translate = Win32::OLE->new('NameTranslate') or die("Unable to load NameTranslate OLE object\n"); # Initialize NameTranslate by locating the Global Catalog. $name_translate->Init(ADS_NAME_INITTYPE_GC, ""); # Use the Set method to specify the NT of the object name. $name_translate->Set(ADS_NAME_TYPE_NT4, $nt_name); # Use the Get method to retrieve the Distinguished Name of the user. my $user_dn = $name_translate->Get(ADS_NAME_TYPE_1779); print("$nt_name => $user_dn\n");

        For me, the output is

        MYDOMAIN\myuser => CN=MyLast\, MyFirst,CN=Users,DC=mycompany,DC=biz