CheWalter Posted September 4, 2012 Share Posted September 4, 2012 Water, First of all thank you for your AD functions, they are OUTSTANDING!!.Now my question: I'm running a simple script that move users from one OU (DisabledUsers) to another OU (ToBeDeleted). It works fine for the first 124 objects, then it gives me errors. I'm including the script, but I think the "124" is the key. I moved the first 124, then I did it with the following 124 and it works, but I can not process more the 124 at the time. I have thousands to move, so moving 124 at the time it will be painful. Is anything obvious that I don't see? Thank you for your time. Walter Link to comment Share on other sites More sharing options...
BrewManNH Posted September 4, 2012 Share Posted September 4, 2012 I don't see your script. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
CheWalter Posted September 4, 2012 Author Share Posted September 4, 2012 Mmm, I attached it but it is not there. Here it is: ; ============================================================================ ; Move all users in a file from one OU to another one ; By Walter 7/11/12 ; ============================================================================ #include <AD.au3> #include<File.au3> ; ---------------------------------------------------------------------------- ; Ask the user to select the input file (must exist, can not be created at this time) $InputFile = FileOpenDialog("File with users to be deleted", @ScriptDir, "Text files (*.txt)", 1 + 2) ; Check for ESC or cancel button If @error Then Exit ; check if file exist (redundant, fileopendialog alredy have the 1+2 If FileExists($InputFile) Then $file = FileOpen($InputFile, 0) Else MsgBox(0, "Error", "File " & $InputFile & " doesn't exist") Exit EndIf ; ---------------------------------------------------------------------------- $OutputPath = @ScriptDir & "DeletedUsers" $SleepTime = 200 $DeletedUsersOU = "OU=Deleted,OU=Disabled,DC=ThisDomain,DC=ORG" ; ---------------------------------------------------------------------------- ; No need to modify anything after this line ; ---------------------------------------------------------------------------- ; ---------------------------------------------------------------------------- ; Open Connection to the Active Directory _AD_Open() ; ---------------------------------------------------------------------------- While 1 ; $file should be separated by tabs with 3 columns; something like this: ; User ID FQDN lastLogonTimestamp ; Administrator "CN=Administrator,CN=Users,DC=ThisDomain,DC=ORG" 08/16/2012 11:40 $line = FileReadLine($file) If @error = -1 Then ; Found EOF ExitLoop EndIf ; ---------------------------------------------------------------------------- $MyArray = StringSplit($line, @TAB) ; If something is wrong, exit If @error Then Exit $MyUserID = $MyArray[1] $MyUserFQDN = StringReplace($MyArray[2], Chr(34), "") ; Not in use right now: $MyLastLogon = $MyArray[3] ; ---------------------------------------------------------------------------- If _AD_ObjectExists($MyUserFQDN) Then ; Get Full/Display name $DispName = _AD_FQDNToDisplayname($MyUserFQDN) If _AD_MoveObject($DeletedUsersOU, $MyUserFQDN) Then ; Show a message ToolTip($MyUserFQDN, 0, 0, "Moved: ") ; Get info to include in the output file $UserAllGroups = _AD_GetUserGroups($MyUserID) $UserAllGroups[0] = $DispName ; Create a file with the UserID as the name $OutputFile = FileOpen($OutputPath & $MyUserID & ".txt", 10) ; Include the user name and all the group membership in the file _FileWriteFromArray($OutputFile, $UserAllGroups, 0) FileClose($OutputFile) ; Just in case, wait for the file to be written on the disk Sleep($SleepTime) Else ; Something went wrong. Show a message MsgBox(0, "Error moving", $MyUserFQDN & ": " & @error) ToolTip($MyUserFQDN, 0, 0, "Error: ") ; Add user id to error file $cmd = @ComSpec & " /c echo " & $MyUserID & " >>ErrorDeleting.txt" RunWait($cmd) EndIf EndIf WEnd ; ---------------------------------------------------------------------------- FileClose($file) _AD_Close() Exit ; ============================================================================ ; ============================================================================ Link to comment Share on other sites More sharing options...
BrewManNH Posted September 4, 2012 Share Posted September 4, 2012 What errors are you getting after the 124th username? And where in your script is the error being thrown from? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
CheWalter Posted September 4, 2012 Author Share Posted September 4, 2012 It shows the message here:; Something went wrong. Show a messageMsgBox(0, "Error moving", $MyUserFQDN & ": " & @error)The message shows the Fully Qualified Domain Name of the user #125 and the error -2147352567. Just in case, I'm using an XP machine and a 2003 ADThank you,Walter Link to comment Share on other sites More sharing options...
water Posted September 4, 2012 Share Posted September 4, 2012 -2147352567 (decimal) is 0x80020009 (hex) and means: DISP_E_EXCEPTION This can be anything. Which version of the UDF do you run (see the header lines at the top of the UDF). 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...
CheWalter Posted September 4, 2012 Author Share Posted September 4, 2012 #include-once #include <Array.au3> #include <Date.au3> #Tidy_Parameters= /gd 1 /gds 1 /nsdp #AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y ; #INDEX# ======================================================================================================================= ; Title .........: Active Directory Function Library ; AutoIt Version : 3.3.6.0 (because of _Date_Time_SystemTimeToDateTimeStr) ; UDF Version ...: 1.1.0 ; Language ......: English ; Description ...: A collection of functions for accessing and manipulating Microsoft Active Directory ; Link to comment Share on other sites More sharing options...
water Posted September 4, 2012 Share Posted September 4, 2012 Could you please insert Global $iAD_Debug = 2after _AD_Open so we get detailed COM error information? 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...
CheWalter Posted September 4, 2012 Author Share Posted September 4, 2012 (edited) I updated to the latest version (UDF Version ...: 1.2.2.0) and now the script crashes in the same place but with this error: C:\Program Files\AutoIt3\Include\AD.au3 (912) : ==> The requested action with this object has failed.: Local $aAD_Groups = $oAD_Object.GetEx("memberof") Local $aAD_Groups = $oAD_Object.GetEx("memberof")^ ERROR ->15:56:11 AutoIT3.exe ended.rc:1 Edited September 4, 2012 by CheWalter Link to comment Share on other sites More sharing options...
water Posted September 5, 2012 Share Posted September 5, 2012 With version 1.2.2.0 you need to use the latest AutoIt beta version. 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...
CheWalter Posted September 5, 2012 Author Share Posted September 5, 2012 I'm going user by user and seems to be I found a rare coincidence: user 125 and 250 belong only to "Domain Users" group. Do you think the function _AD_GetUserGroups may fail when this happens? I installed the latest autoit beta. Thank you Link to comment Share on other sites More sharing options...
CheWalter Posted September 5, 2012 Author Share Posted September 5, 2012 I'm answering myself :-)Yes, the problem was the function _AD_GetUserGroups. If the user ONLY belongs to "Domain Users", then it crashes.The idea for the solution came from http://www.autoitscript.com/autoit3/docs/functions/ObjEvent.htmI added at the beginning of the function an "event trap", so function looks like this:Func _AD_GetUserGroups($sAD_User = @UserName, $bAD_IncludePrimaryGroup = False) ; Added by Walter $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") ; If _AD_ObjectExists($sAD_User) = 0 Then Return SetError(1, 0, "") Local $sAD_Property = "sAMAccountName" If StringMid($sAD_User, 3, 1) = "=" Then $sAD_Property = "distinguishedName" ; FQDN provided $__oAD_Command.CommandText = "<LDAP://" & $sAD_HostServer & "/" & $sAD_DNSDomain & ">;(" & $sAD_Property & "=" & $sAD_User & ");ADsPath;subtree" Local $oAD_RecordSet = $__oAD_Command.Execute ; Retrieve the FQDN for the logged on user Local $sAD_LDAPEntry = $oAD_RecordSet.fields(0).value Local $oAD_Object = __AD_ObjGet($sAD_LDAPEntry) ; Retrieve the COM Object for the logged on user Local $aAD_Groups = $oAD_Object.GetEx("memberof")If IsArray($aAD_Groups) Then If $bAD_IncludePrimaryGroup Then _ArrayAdd($aAD_Groups, _AD_GetUserPrimaryGroup($sAD_User)) _ArrayInsert($aAD_Groups, 0, UBound($aAD_Groups)) Else Local $aAD_Groups[1] = [0] If $bAD_IncludePrimaryGroup Then _ArrayAdd($aAD_Groups, _AD_GetUserPrimaryGroup($sAD_User)) $aAD_Groups[0] = UBound($aAD_Groups) - 1 EndIf Return $aAD_Groups ; Added by Walter #forceref $oErrorHandler EndFunc ;==>_AD_GetUserGroupsThen I added the function in AD.au3Func _ErrFunc($oError) Local $msg $msg = "err.number is: " & @TAB & $oError.number & @CRLF $msg = $msg & "err.windescription:" & @TAB & $oError.windescription & @CRLF $msg = $msg & "err.description is: " & @TAB & $oError.description & @CRLF $msg = $msg & "err.source is: " & @TAB & $oError.source & @CRLF $msg = $msg & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF $msg = $msg & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF $msg = $msg & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF $msg = $msg & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF $msg = $msg & "err.retcode is: " & @TAB & $oError.retcode & @CRLF MsgBox(0, "Error trap", $msg) EndFunc ;==>_ErrFuncIt works now.Thank you all for spending time helping me.Walter Link to comment Share on other sites More sharing options...
Bowmore Posted September 5, 2012 Share Posted September 5, 2012 Thanks for posting the solution to a problem you managed to solve yourself thus enabling others to benefit from your experience. CheWalter 1 "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
water Posted September 5, 2012 Share Posted September 5, 2012 (edited) The COM error handler is not needed if you run version 1.2.2.0 of the UDF AND the latest beta version of AutoIt.If you run version 1.2.2.0 of the UDF AND one of the production versions of AutoIt you need to enable the COM error handler by calling_AD_ErrorNotify(1)at the top of your script (this combination is not recommended).Version 1.2.0 of the UDF goes well with AutoIt 3.3.8.1Version 1.2.2.0 of the UDF goes well with AutoIt 3.3.9.2 beta or later Edited September 5, 2012 by water CheWalter 1 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...
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