antmar904 Posted July 23, 2018 Posted July 23, 2018 Hi I'm trying to run my script "ADCleanup.exe" with a command line parameter "-user". I am able to run my script with a parameter but how would I go about "labeling" my parameter and checking if the script is being run with that parameter? Exp: ADCleanup.exe -user <users name> If Not $CmdLine[1] = "" Then _Revert() EndIf
FrancescoDiMuro Posted July 23, 2018 Posted July 23, 2018 (edited) @antmar904 Since in the $CmdLine array, the first element in the array is the number of elements in the array ( the parameters you pass to the executable ), you could do somethingle like: If $CmdLine[0] <> 0 Then If $CmdLine[1] = "-user" Then Select Case $CmdLine[2] = "John" Then ; Execute the code for yhe user John Case $CmdLine[2] = "Ron" ; Execute the code for user Ron Case Else ; ... EndSelect Else MsgBox($MB_ICONWARNING, "", "Wrong parameter entered.) EndIf Else MsgBox($MB_ICONERROR, "", "No command line parameters passed to the script.) EndIf EDIT: You could use a Select...Case...EndSelect as well for the "labelled" parameters Edited July 23, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
antmar904 Posted July 23, 2018 Author Posted July 23, 2018 @FrancescoDiMuro I won't know what comes after -user. How would I check what that is ? $CmdLine[3] ?
FrancescoDiMuro Posted July 23, 2018 Posted July 23, 2018 You are the programmer... You should know How do you intend to program your script? What are the parameters you would like to pass to the script? Making example it's a good point from start to Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
antmar904 Posted July 23, 2018 Author Posted July 23, 2018 I used this and looks like it's working: If $CmdLine[0] <> 0 Then If $CmdLine[1] = "-revert" Then _Revert() Else MsgBox($MB_ICONWARNING, "", "Wrong parameter entered.") EndIf EndIf
FrancescoDiMuro Posted July 23, 2018 Posted July 23, 2018 It only depends from what you'd like to do Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
antmar904 Posted July 23, 2018 Author Posted July 23, 2018 Yes this works as needed. I'm also trying to find a way to read a txt file from the end to the beginning.
FrancescoDiMuro Posted July 23, 2018 Posted July 23, 2018 (edited) What about a combination of FileSetPos() and FileRead() or directly _FileReadToArray() ? Edited July 23, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
antmar904 Posted July 23, 2018 Author Posted July 23, 2018 _FileReadToArray() would probably be the best way to go. Was not sure if there was something easier as I'm not the best when working with arrays.
antmar904 Posted July 23, 2018 Author Posted July 23, 2018 I'm still trying to find out how I can check if the script .exe is ran with the correct parameters. ADCleanup.exe -user <users name> How would I go about checking to make sure something is followed after -user like a user name? Exp: ADCleanup.exe -user usaaab1
FrancescoDiMuro Posted July 23, 2018 Posted July 23, 2018 The thing you have to be sure, is that in the first parameter you are passing to the script, there will always be an username. According to this, when you run the script with ScriptName.exe -user "John" You can easily make an If...Else...EndIf statement, or, in my honest opinion, you can do it clearly with Select...Case...EndSelect statement. Is it clear? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
antmar904 Posted July 24, 2018 Author Posted July 24, 2018 16 hours ago, FrancescoDiMuro said: What about a combination of FileSetPos() and FileRead() or directly _FileReadToArray() ? I have txt file that I would like to read from the bottom to the top while looking for a specific string in each line (username). The txt file is formatted in a way that each data is delimited by a semicolon ":" Here is a sample of the txt file content. 07232018_161504(usera): usaaxftest:OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com:UNABLE TO MOVE 07232018_161504(usera): asdfasdf:NOT FOUND 07232018_161504(usera): asdfasdf:NOT FOUND 07232018_161504(usera): asfdgadfh:NOT FOUND 07232018_161504(usera): adfhsfgn bsdfgbs:NOT FOUND 07232018_161504(usera): asdgf:NOT FOUND 07232018_161504(usera): asfgdadfghad:NOT FOUND 07232018_161504(usera): fhasdfnbfsbfg:NOT FOUND 07232018_161504(usera): sf:NOT FOUND 07232018_161504(usera): gbsdgfbsdbgf:NOT FOUND 07232018_161504(usera): sdfgb:NOT FOUND 07232018_161504(usera): sdfg:NOT FOUND 07232018_161504(usera): sdfg:NOT FOUND 07232018_161504(usera): sdfgsdfg:NOT FOUND 07232018_162815(usera): usaaxftest2:OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com:UNABLE TO MOVE 07232018_162815(usera): asdf:NOT FOUND07232018_162815(usera): usaaxftest:OU=General Users,OU=Users,OU=USA,DC=na,DC=domain,DC=com:UNABLE TO MOVE 07232018_162815(usera): asdfasdf:NOT FOUND 07232018_162815(usera): asdfasdf:NOT FOUND 07232018_162815(usera): asfdgadfh:NOT FOUND 07232018_162815(usera): adfhsfgn bsdfgbs:NOT FOUND 07232018_162815(usera): asdgf:NOT FOUND 07232018_162815(usera): asfgdadfghad:NOT FOUND 07232018_162815(usera): fhasdfnbfsbfg:NOT FOUND 07232018_162815(usera): sf:NOT FOUND 07232018_162815(usera): gbsdgfbsdbgf:NOT FOUND 07232018_162815(usera): sdfgb:NOT FOUND 07232018_162815(usera): sdfg:NOT FOUND 07232018_162815(usera): sdfg:NOT FOUND 07232018_162815(usera): sdfgsdfg:NOT FOUND 07232018_163528(usera): usaaxftest2:OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com:UNABLE TO MOVE 07232018_163528(usera): asdf:NOT FOUND 07232018_163528(usera): usaaxftest:OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com:UNABLE TO MOVE 07232018_163528(usera): asdfasdf:NOT FOUND 07232018_163528(usera): asdfasdf:NOT FOUND 07232018_163528(usera): asfdgadfh:NOT FOUND 07232018_163528(usera): adfhsfgn bsdfgbs:NOT FOUND 07232018_163528(usera): asdgf:NOT FOUND 07232018_163528(usera): asfgdadfghad:NOT FOUND 07232018_163528(usera): fhasdfnbfsbfg:NOT FOUND 07232018_163528(usera): sf:NOT FOUND 07232018_163528(usera): gbsdgfbsdbgf:NOT FOUND 07232018_163528(usera): sdfgb:NOT FOUND 07232018_163528(usera): sdfg:NOT FOUND 07232018_163528(usera): sdfg:NOT FOUND 07232018_163528(usera): sdfgsdfg:NOT FOUND I would like to look for user "usaaxftest" starting from the bottom of the file to the top BUT if user usaaxftest is located in this "OU OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com" then skip that line and go to the next line above until it find user "usaaxftest" in a different OU.
FrancescoDiMuro Posted July 24, 2018 Posted July 24, 2018 (edited) What about this? #include <File.au3> Global $strFileName = @ScriptDir & "\File.txt", _ $arrFileContent, _ $strSearchString = "usaaxftest:OU=General Users,OU=Users,OU=USA,DC=na,DC=domain,DC=com:UNABLE TO MOVE" ; Read the content of the file in the array _FileReadToArray($strFileName, $arrFileContent) If @error Then ConsoleWrite("Error while reading the file into the array. Error: " & @error & @CRLF) Else ; From the last element of the array, to the second ( because in the first element there is the count of lines returned by the function _FileReadToArray() ), with the Step of -1 ( because it is going from bottom to top ), seacrh the specified string For $i = UBound($arrFileContent) - 1 To 1 Step -1 ; If it has been found, write this message If StringInStr($arrFileContent[$i], $strSearchString) Then ConsoleWrite("I've found '" & $strSearchString & "' at the Index " & $i & @CRLF) Else ContinueLoop EndIf Next EndIf Edited July 24, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
antmar904 Posted July 24, 2018 Author Posted July 24, 2018 I tried this but this starts at the beginning of the file and reads to the end. However if the string contains ":OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com" AT ALL it fill fail. #include <File.au3> #include <AutoItConstants.au3> #include <StringConstants.au3> Local $aArray _FileReadToArray(@ScriptDir & "\ADCleanupLog.txt", $aArray) _ArrayDisplay($aArray) Local $iRow = UBound($aArray, 1) MsgBox(0, "", "Number of rows are: " & $iRow) For $i = 0 To UBound($aArray, 1) - 1 If StringInStr($aArray[$i], "OU=Disabled,OU=Antiquated,DC=na,DC=praxair,DC=com", 2) Then ContinueLoop Else MsgBox(0, "", $aArray[$i]) EndIf Next Exit
FrancescoDiMuro Posted July 24, 2018 Posted July 24, 2018 Did you read this? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
antmar904 Posted July 24, 2018 Author Posted July 24, 2018 12 minutes ago, FrancescoDiMuro said: What about this? #include <File.au3> Global $strFileName = @ScriptDir & "\File.txt", _ $arrFileContent, _ $strSearchString = "usaaxftest:OU=General Users,OU=Users,OU=USA,DC=na,DC=domain,DC=com:UNABLE TO MOVE" ; Read the content of the file in the array _FileReadToArray($strFileName, $arrFileContent) If @error Then ConsoleWrite("Error while reading the file into the array. Error: " & @error & @CRLF) Else ; From the last element of the array, to the second ( because in the first element there is the count of lines returned by the function _FileReadToArray() ), with the Step of -1 ( because it is going from bottom to top ), seacrh the specified string For $i = UBound($arrFileContent) - 1 To 1 Step -1 ; If it has been found, write this message If StringInStr($arrFileContent[$i], $strSearchString) Then ConsoleWrite("I've found '" & $strSearchString & "' at the Index " & $i & @CRLF) Else ContinueLoop EndIf Next EndIf I want to find out what OU the user was in before they were moved to the "OU=Disabled,OU=Antiquated,DC=na,DC=praxair,DC=com" OU so I want to SKIP that line and move on to the next.
FrancescoDiMuro Posted July 24, 2018 Posted July 24, 2018 So, you are looking for the user that HAS NOT OU=Disabled? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
antmar904 Posted July 24, 2018 Author Posted July 24, 2018 (edited) Correct. My script will run like this. ADCleanup.exe -revert usaaxftest OR some other user name. The script will then read the txt file from bottom to top until it finds the user name "usaaxftest" AND NOT in OU "OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com" however "OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com" might be in the string because the way the log file is formatted. Here is the format of the log file. Line: 07232018_145925(usera): usaaxftest:OU=General Users,OU=Users,OU=USA,DC=na,DC=domain,DC=com:OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com 07232018_145925 = Date script was ran (usera) = User who ran the script usaaxftest = User that was moved <-- could be any user name OU=General Users,OU=Users,OU=USA,DC=na,DC=domain,DC=com = The users current OU <-- Can be anything depending on were the user is currently located in AD OU=Disabled,OU=Antiquated,DC=na,DC=domain,DC=com = The OU the user is moved to when being disabled. <-- Depending on how many times the script is ran, this can show up for the users current and new OU location. All information is delimited by a ":" Does this make sense? Edited July 24, 2018 by antmar904
Earthshine Posted July 24, 2018 Posted July 24, 2018 (edited) starting with that example code, you could code up a function to do the checking, then other functions to do your execution bidding Edited July 24, 2018 by Earthshine My resources are limited. You must ask the right questions
antmar904 Posted July 24, 2018 Author Posted July 24, 2018 (edited) how can I skip Row 0 in a array? Edited July 24, 2018 by antmar904
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