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"); #### MYDOMAIN\myuser => CN=MyLast\, MyFirst,CN=Users,DC=mycompany,DC=biz