in reply to Re: convert the SamAccountName to the Distinguished name by using "NameTranslate"
in thread convert the SamAccountName to the Distinguished name by using "NameTranslate"

I think, he is refering to this page

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^3: convert the SamAccountName to the Distinguished name by using "NameTranslate"
by ikegami (Patriarch) on Sep 06, 2006 at 16:17 UTC
    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