Sign in to follow this  
Followers 0
stev379

NameTranslate - Last, First convert to username

2 posts in this topic

I got a longer version of the code below from AutoIT a couple years ago. Today, I stripped it down so it only translates the name. However it's doing it backwards.

How can I translate names from "LAST NAME, FIRST NAME" to "USERNAME"?

Example: Smith, John translated to jsmith or whatever the AD username is.

I have a spreadsheet with a column containing lastname, firstname, but I can copy it to a text file to handle the reading a little easier. I just need a way to convert all the names into the usernames and then I can add them to a group. I have a VBS script to add them to the group, but it only works with usernames.

Thanks!

; Change input to be at the top of the window...maybe
; Add function to click a button and open the user's logon script in Edit view
; display home drive connection

#include 
#include 
#include 
#include 

Const $ADS_NAME_INITTYPE_GC = 3
Const $ADS_NAME_TYPE_NT4 = 3
Const $ADS_NAME_TYPE_1779 = 1
DIM $unlock
DIM $mgrvalue
DIM $mgrsplit
DIM $manager
DIM $mgr
DIM $title
DIM $pwdexpires
Dim $arrLOGONSCRIPT[100]
$oMyError = ObjEvent("AutoIt.Error", "ComError")
$objRootDSE = ObjGet("LDAP://RootDSE")
$username = InputBox("Username","Please input a username:")
If @error Then
MsgBox(0, 'username', 'Username does not exist or not able to communicate with ' & @LogonDomain)
Else
; DNS domain name.
$objTrans = ObjCreate("NameTranslate")
$objTrans.Init ($ADS_NAME_INITTYPE_GC, "")
$objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain)
$objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & $username)
$strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779)
$UserObj = ObjGet("LDAP://" & $strUserDN)
If @error Then
MsgBox(0, 'username', 'Username does not exist or not able to communicate with ' & @LogonDomain)
Else
Call ("Displayinfo")

EndIf
EndIf
$UserObj = ""
$oMyError = ObjEvent("AutoIt.Error", "")
;COM Error function
Func ComError()
If IsObj($oMyError) Then
$HexNumber = Hex($oMyError.number, 8)
SetError($HexNumber)
Else
SetError(1)
EndIf
Return 0
EndFunc ;==>ComError


Func Displayinfo()

MsgBox(0, '', "Full name: " & $UserObj.FirstName & " " & $UserObj.LastName)

EndFunc

Share this post


Link to post
Share on other sites



For the AD stuff you can use my Active Directory UDF (for download please see my signature).

To search for the user use function _AD_GetObjectsInOU.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0