stev379 Posted July 31, 2012 Posted July 31, 2012 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!expandcollapse popup; 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
water Posted August 1, 2012 Posted August 1, 2012 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now