VAADAdmin Posted November 27, 2006 Posted November 27, 2006 I am creating a script to copy a template user in Active Directory. I have gotten the add a new user to work but having problems copying a user. It seems to be related to the For Next statement at line 130. Error is variable must be of type "object". I am new to this scripting and the array is killing me and the mess that I call a script. I am trying to get it to work then I will clean it and make it look pretty as I learn more. Any help would be appreciated. I did the conversion from VBS to AutoIT with the script but still have issues. expandcollapse popup;Include constants #include <GUIConstants.au3> #include <GUICombo.au3> ;Initialize variables Global $GUIWidth Global $GUIHeight $GUIWidth = 600 $GUIHeight = 500 ;Create window GUICreate("Organizational Unit", $GUIWidth, $GUIHeight) ;Create an edit box with no text in it ;$Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190) ;Create a "Next" button $CreateUser_Btn = GUICtrlCreateButton("Create User", 100, 400, 70, 25) ;Create a "CANCEL" button $Cancel_Btn = GUICtrlCreateButton("Cancel", 175, 400, 70, 25) ;Create a "DropDown" box $Combo_Box = GUICtrlCreateCombo("Select OU", 75, 100, 500, 10) ;Create Input Box $Lbl_firstName =GUICtrlCreateInput("First Name", 75, 50, 100, 20) ;Create Input Box $Lbl_MI =GUICtrlCreateInput("M.I.", 185, 50, 25, 20) ;Create Input Box $Lbl_lastName =GUICtrlCreateInput("Last Name", 220, 50, 200, 20) ;Show window/Make the window visible GUISetState(@SW_SHOW) ;Loop until: ;- user presses Esc ;- user presses Alt+F4 ;- user clicks the close button ;Populate ComboBox with OU's Local $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<GC://ou=User-Accounts,dc=xxxxxx,dc=xxxxx>" Local $strFilter = "(objectCategory=organizationalUnit)" Local $strAttributes = "distinguishedName" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties ("Page Size") = 100 $objCommand.Properties ("Timeout") = 30 $objCommand.Properties ("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute While Not $objRecordSet.EOF $strdistinguishedName = $objRecordSet.Fields("distinguishedName").value GUICtrlSetData(5,$strdistinguishedName) $objRecordSet.MoveNext Wend ;Variables While 1 ;After every loop check if the user clicked something in the GUI window $msg = GUIGetMsg() $destinationOU=GUICtrlRead($Combo_Box) $firstName=GUICtrlRead(6) $lastName=GUICtrlRead(8) $userName = ("testsiegman") Select ;Check if user clicked on the close button Case $msg = $GUI_EVENT_CLOSE ;Destroy the GUI including the controls GUIDelete() ;Exit the script Exit ;Check if user clicked on the "OK" button Case $msg = $CreateUser_Btn $testTemplate=("ttempl" & $destinationOU) Global $Array[4] $Array[0]="department" $Array[1]="l" $Array[2]="c" $Array[3]="st" ;$arrAttrs = $Array Select Case $destinationOU=("OU=TEST OU,OU=User-Accounts,DC=xxxxxx,DC=xxxxxx") $objTemplate = ObjGet("LDAP://" & "cn=" & $testTemplate) $objParent = ObjGet("LDAP://" & $destinationOU) $objUser = $objParent.Create("user", "cn=" & $userName) $objUser.Put ("sAMAccountName",$userName) ;$objUser.Put ("userAccountControl", ADS_UF_NORMAL_ACCOUNT) Const $ADS_UF_NORMAL_ACCOUNT = 512 ; from ADS_USER_FLAG_ENUM ;$objUser.Put ($sAMAccountName, $strNewUser) For $strAttr in $Array $objUser.Put ($strAttr, $objTemplate.objGet($strAttr)) next $objUser.SetInfo $objUser.SetPassword("xxxxxxxxx") $objUser.SetInfo $objUser.Put ("userAccountControl", $ADS_UF_NORMAL_ACCOUNT) $objUser.AccountDisabled = 0 $objUser.SetInfo MsgBox(64, "User Creation", $firstName & $lastName & "Has been Created in" & $destinationOU) EndSelect #comments-start $objParent = ObjGet("LDAP://" & $destinationOU) $objUser = $objParent.Create("user", "cn=" & $userName) $objUser.Put ("givenName", $firstName) $objUser.Put ("sAMAccountName",$userName) $objUser.Put ("sn", $lastName) $objUser.SetInfo $objUser.SetPassword("Perot2006!") $objUser.AccountDisabled = True $objUser.SetInfo MsgBox(64, "User Creation", $firstName & $lastName & "Has been Created in" & $destinationOU) #comments-end ;Check if user clicked on the "CANCEL" button Case $msg = $Cancel_Btn ;MsgBox(64, "New GUI", "You clicked on the Cancel button!") ;Destroy the GUI including the controls GUIDelete() ;Exit the script Exit EndSelect WEnd $objConnection.Close $objConnection = "" $objCommand = "" $objRecordSet = ""
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