Spikemg1 Posted November 29, 2018 Author Share Posted November 29, 2018 3 hours ago, water said: Sure: MsgBox(1, 'Review User Info', _ 'First Name: ' & $givenName _ & @CRLF & 'Last Name: ' & $surName _ & @CRLF & 'LogOn Name: '& $iuserName _ & @CRLF & 'User Destination:' & GUICtrlRead($itemBox1) _ & @CRLF) Details can be found in the help file: https://www.autoitscript.com/autoit3/docs/intro/lang_comments.htm Nice thanks for the link. Now the current hurdle I'm working on, is searching for a specific user from the OU in a combo box. Then When selecting that user it copies all user properties over to the new user being created. Link to comment Share on other sites More sharing options...
Spikemg1 Posted November 30, 2018 Author Share Posted November 30, 2018 Am I missing something? ;Check for user logon name $iuserName = GUICtrlRead($userName & @CRLF) If $iuserName <> '' Then ConsoleWrite($iuserName & @CRLF) ElseIf _AD_ObjectExists($iuserName = @UserName) Then MsgBox(0, 'Error', 'LogOn name is already taken.') Else MsgBox(0, 'Error', 'Please provide a user logon name.') EndIf Link to comment Share on other sites More sharing options...
water Posted November 30, 2018 Share Posted November 30, 2018 This line is wrong: ElseIf _AD_ObjectExists($iuserName = @UserName) Then Function _AD_ObjectExists checks if an object (user, computer ...) exists. What do you want to achieve with this line? 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 Link to comment Share on other sites More sharing options...
Spikemg1 Posted November 30, 2018 Author Share Posted November 30, 2018 (edited) 21 minutes ago, water said: This line is wrong: ElseIf _AD_ObjectExists($iuserName = @UserName) Then Function _AD_ObjectExists checks if an object (user, computer ...) exists. What do you want to achieve with this line? I want it to pop a msgbox if the user logon name matches another user already in the OU. to prevent multiple users with the same logon name. Edited November 30, 2018 by Spikemg1 Link to comment Share on other sites More sharing options...
water Posted November 30, 2018 Share Posted November 30, 2018 Use function _AD_GetObjectsInOU and pass the OU to search as parameter 1. Check the examples in the example script _AD_GetObjectsInOU.au3. 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 Link to comment Share on other sites More sharing options...
Spikemg1 Posted December 18, 2018 Author Share Posted December 18, 2018 Here is my most recent script update. expandcollapse popup#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y #include <AD.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> ;Opens a connection to Active Directory _AD_Open() If @error Then Exit MsgBox(16, "Active Directory Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended) #Region ;Global Variables Global $aOUs = _AD_GetAllOUs() Global $callOU = ObjCreate("Scripting.Dictionary") Global $itemBoxOptions1 = "" Global $itemBoxOptions2 = "" Global $itemBox1, $itemBox2 Global $firstName, $givenName Global $lastName, $surName Global $iuserName, $userName Global $userEmail Global $Combo1, $Combo2 Global $foundUser #EndRegion #Region ;GUI Creation Global $Form1_1_1 = GUICreate("Tab Sheet Ver. 1.0.0", 757, 452, 192, 143) ;AD Tab 1 GUICtrlCreateTab(0, 0, 753, 449) ;Group 1 of AD Tab Global $TabSheet1 = GUICtrlCreateTabItem("ActiveDirectory") Global $ADGroup1 = GUICtrlCreateGroup("AD User Name", 8, 32, 737, 105) ;First Name Global $Label3 = GUICtrlCreateLabel("First Name", 16, 51, 54, 17) $firstName = GUICtrlCreateInput("", 80, 51, 225, 21) ;Last Name Global $Label2 = GUICtrlCreateLabel("Last Name", 16, 75, 55, 17) $lastName = GUICtrlCreateInput("", 80, 75, 225, 21) ;LogOn Name Global $Label1 = GUICtrlCreateLabel("User LogOn Name", 16, 107, 92, 17) $userName = GUICtrlCreateInput("", 112, 107, 201, 21) ;Copy From Template User Global $Label4 = GUICtrlCreateLabel("Copy From", 320, 91, 54, 17) $Combo2 = GUICtrlCreateCombo("", 392, 91, 345, 25, BitOR($CBS_DROPDOWN,$WS_VSCROLL)) ;Determines Where the New User Goes in AD Global $Label5 = GUICtrlCreateLabel("Folder Location", 312, 48, 77, 17) $Combo1 = GUICtrlCreateCombo("", 392, 48, 345, 25, BitOR($CBS_DROPDOWN,$WS_VSCROLL)) For $iOU = 1 to $aOUs[0][0] $callOU.Add($aOUs[$iOU][0] , $aOUs[$iOU][1]) If($itemBoxOptions1 = "") Then $itemBoxOptions1 = $aOUs[$iOU][0] Else $itemBoxOptions1 = $itemBoxOptions1 & "|" & $aOUs[$iOU][0] EndIf Next $itemBox1 = GUictrlread($itemBoxOptions1) GUICtrlSetData($Combo1, $itemBoxOptions1 , 'WCHUsers\TEST') ;End of AD Tab Group 1 ;Group 2 of AD Tab GUICtrlCreateGroup("", -99, -99, 1, 1) Global $ADGroup2 = GUICtrlCreateGroup("AD Password", 8, 144, 737, 121) Global $Label7 = GUICtrlCreateLabel("Password", 16, 168, 50, 17) Global $Label8 = GUICtrlCreateLabel("Confirm", 16, 192, 39, 17) Global $PasswordInput = GUICtrlCreateInput("", 72, 168, 217, 21, $ES_PASSWORD) Global $ConfirmInput = GUICtrlCreateInput("", 64, 192, 225, 21, $ES_PASSWORD) Global $PassWord = GUICtrlRead($ConfirmInput) Global $Checkbox1 = GUICtrlCreateCheckbox("User must change password at next logon", 312, 160, 289, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $Checkbox2 = GUICtrlCreateCheckbox("User cannot change password", 312, 184, 289, 17) Global $Checkbox3 = GUICtrlCreateCheckbox("Password never expires", 312, 208, 289, 17) Global $Checkbox4 = GUICtrlCreateCheckbox("Account is disabled", 312, 232, 289, 17) ;End of AD Tab group 2 ;AD Tab 2 Global $TabSheet2 = GUICtrlCreateTabItem("More AD Info") Global $Group1 = GUICtrlCreateGroup("Additional Information", 4, 27, 737, 505) Global $Label20 = GUICtrlCreateLabel("Home Phone", 12, 51, 66, 17) Global $Input4 = GUICtrlCreateInput("", 84, 51, 201, 21) Global $Label21 = GUICtrlCreateLabel("Cell Phone", 12, 75, 55, 17) Global $Input5 = GUICtrlCreateInput("", 84, 75, 201, 21) Global $Label22 = GUICtrlCreateLabel("Office Phone", 12, 99, 66, 17) Global $Input6 = GUICtrlCreateInput("", 84, 99, 201, 21) Global $Label23 = GUICtrlCreateLabel("Street Address", 292, 43, 73, 17) Global $Edit1 = GUICtrlCreateEdit("", 372, 43, 353, 113) Global $Label24 = GUICtrlCreateLabel("P.O. Box", 300, 163, 46, 17) Global $Input7 = GUICtrlCreateInput("", 372, 163, 353, 21) Global $Label25 = GUICtrlCreateLabel("City", 300, 187, 21, 17) Global $Input8 = GUICtrlCreateInput("", 372, 187, 353, 21) Global $Label26 = GUICtrlCreateLabel("State/Province", 300, 211, 76, 17) Global $Input9 = GUICtrlCreateInput("", 388, 211, 337, 21) Global $Label27 = GUICtrlCreateLabel("Zip/Postal Code", 300, 235, 81, 17) Global $Input10 = GUICtrlCreateInput("", 388, 235, 337, 21) Global $Label28 = GUICtrlCreateLabel("Email", 12, 123, 29, 17) Global $Input11 = GUICtrlCreateInput("", 84, 123, 201, 21) Global $Label29 = GUICtrlCreateLabel("Fax", 12, 147, 21, 17) Global $Input12 = GUICtrlCreateInput("", 84, 147, 201, 21) Global $Label30 = GUICtrlCreateLabel("Job Title", 12, 171, 44, 17) Global $Input13 = GUICtrlCreateInput("", 84, 171, 201, 21) Global $Label31 = GUICtrlCreateLabel("Department", 12, 195, 59, 17) Global $Input14 = GUICtrlCreateInput("", 84, 195, 201, 21) Global $Label32 = GUICtrlCreateLabel("Description", 12, 219, 57, 17) Global $Edit2 = GUICtrlCreateEdit("", 84, 219, 201, 57) GUICtrlSetData(-1, "Description") Global $Label6 = GUICtrlCreateLabel("Employee Number", 8, 288, 90, 17) Global $EmpNumber = GUICtrlCreateInput("", 104, 288, 185, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateTabItem("") Global $CreateButton = GUICtrlCreateButton("Create Account", 568, 416, 91, 25) Global $ExitButton = GUICtrlCreateButton("Exit", 664, 416, 75, 25) ;End of AD Tab Sheet============================================================= #EndRegion While 1 Global $nMsg = GUIGetMsg() Switch $nMsg Case $CreateButton ;Missing Input Errors ;Check for user first name $givenName = GUICtrlRead($firstName) If $givenName <> '' Then ConsoleWrite($givenName & @CRLF) Else MsgBox(0, 'error', 'Please provide user first name.') EndIf ;Check for user last name $surName = GUICtrlRead($lastName) If $surName <> '' Then ConsoleWrite($surName & @CRLF) Else MsgBox(0, 'Error', 'Please provide user last name.') EndIf ;Check for user logon name $iuserName = GUICtrlRead($userName) If $iuserName <> '' Then ConsoleWrite($iuserName & @CRLF) Else MsgBox(0, 'Error', 'Please provide a user logon name.') EndIf ;Check for matching passwords If GUICtrlRead($PasswordInput) <> GUICtrlRead($ConfirmInput) Then MsgBox(16, "Error", "Passwords do not match.") EndIf ;Check for user email ;$userEmail = GUICtrlRead($iuserEmail) ;If $userEmail <> '' Then ; ConsoleWrite($userEmail & @CRLF) ;Else ; MsgBox(0, 'Error', 'Please provide user email.') ;EndIf ;Review User Entry Msgbox If Not IsDeclared("reviewMsgBox") Then Global $reviewMsgBox $reviewMsgBox = MsgBox(8497,"Review User Info", _ "First Name:" & $givenName & @CRLF _ & "Last Name:" & $surName & @CRLF _ & "Logon Name:" & $iuserName & @CRLF _ & "Account Destination:" & GUICtrlRead($Combo1) & @CRLF _ & "Copied From:" & GUICtrlRead($Combo2) & @CRLF _ & "Email Address:" & @CRLF) Select Case $reviewMsgBox = 1 ;OK ;Run('powershell_ise.exe') ;Global $pShell = WinWait("[CLASS:Powershell ISE]", "", 2) ;Sleep(2000) ;Send('^i') ;Send('New-ADUSer ' & _ ;Create New User ConsoleWrite('New-ADUSer ' & _ ;Create New User '-ChangePasswordAtLogon $True ' & _ ;Change Password At Logon Yes '-AccountPassword (Read-Host -AsSecureString ' & GUICtrlRead($PasswordInput) & ')' & _ ' -Path ' & _ ;OU Destination ' -SamAccountName ' & $iuserName & _ ;User Name ' -Department ' & _ ;Department ' -DisplayName ' & $givenName & ' ' & $surName & _ ;Display Name ' -EmailAddress ' & _ ;Email Account ' -EmployeeID ' & _ ;Employee # ' -Fax ' & _ ;Fax # ' -GivenName ' & $givenName & _ ;First Name ' -SurName ' & $surName & _ ;Last Name ' -Initials ' & _ ;Middle Initial ' -HomePhone ' & _ ;Phone # ' -MobilePhone ' & _ ;Cell # ' -OfficePhone ' & _ ;Office # ' -Description ' & _ ;Description for Account ' -') ;Sleep(500) ;Send('{F5}') Case $reviewMsgBox = 2 ;Cancel EndSelect Case $ExitButton Exit Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ;Close connection to Active Directory _AD_Close() Link to comment Share on other sites More sharing options...
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