Jump to content
31290

[Solved] AD update from csv file

Recommended Posts

 

Hi guys, 

I'd like to write a piece of tool that would allow me to update a certain field in our Active Directory from a comma separated csv file composed like this:

2017-02-24_15-59-49.png

This file, automatically generated, can hold more than 10k lines.
Thus, I need column A to be in one variable, column B in a second one and column C in a third one.

I'm really missing this part as updating the AD is fairly easy once the 3 variable are populated. 

I see things like this:

Quote

Read line 1
Do AD update
Read line 2
Do AD update
...
End Of File

Here's my attempts at the moment:

#include <File.au3>
#include <Array.au3>

Global $csv_file = @DesktopDir & "\Book1.csv"
Global $aRecords

If Not _FileReadToArray($csv_file,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    Msgbox(0,'Record:' & $x, $aRecords[$x]) ; Shows the line that was read from file
    $csv_line_values = StringSplit($aRecords[$x], ",",1) ; Splits the line into 2 or more variables and puts them in an array
    ; _ArrayDisplay($csv_line_values) ; Shows what's in the array you just created.
    ; $csv_line_values[0] holds the number of elements in array
    ; $csv_line_values[1] holds the value
    ; $csv_line_values[2] holds the value
    ; etc
    Msgbox(0, 0, $csv_line_values[1])
Next

Any help on this please? 

Thanks in advance

-31290-

Edited by 31290
solved

~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites
#include <File.au3>
#include <Array.au3>

Global $csv_file = @DesktopDir & "\Book1.csv"
Global $aRecords

If Not _FileReadToArray($csv_file,$aRecords) Then
  ; MsgBox(4096,"Error", " Error reading log to Array error:" & @error)
   Exit
EndIf


For $x = 1 to UBound($aRecords) -1
   ConsoleWrite("ROW "&$x &" "&$aRecords[$x]&@CRLF) ; Shows the line that was read from file
    $csv_line_values = StringSplit($aRecords[$x], ",",1) ; Splits the line into 2 or more variables and puts them in an array
   For $z = 1 to UBound($csv_line_values) -1
        If $z = 1 Then
            ConsoleWrite(" A " &$csv_line_values[$z]&@CRLF)
        ElseIf $z = 2 Then
            ConsoleWrite(" B " &$csv_line_values[$z]&@CRLF)
        ElseIf $z = 3 Then
            ConsoleWrite(" C " &$csv_line_values[$z]&@CRLF)
        EndIf
    Next
   ; _ArrayDisplay($csv_line_values) ; Shows what's in the array you just created.
    ; $csv_line_values[0] holds the number of elements in array
    ; $csv_line_values[1] holds the value
    ; $csv_line_values[2] holds the value
    ; etc
   ; Msgbox(0, 0, $csv_line_values[1])
Next

 

Share this post


Link to post
Share on other sites

Would like to add you can also use Excel UDF to create your array

#include <Array.au3> ;~ Only required for _ArrayDisplay()
#include <Excel.au3>

;~ Excel File (.xlxx, .csv) file path
$sExcelFile = @DesktopDir & "\Book1.csv"
;~ Open Excel Object
$oExcel = _Excel_Open (False)
;~ Open the Workbook
$oWorkbook = _Excel_BookOpen($oExcel, $sExcelFile, True, False)
;~ Read the Workbook to an array
$aArray = _Excel_RangeRead($oWorkbook)

;~ Display the Array
_ArrayDisplay($aArray)

;~ Close the WorkBook
_Excel_BookClose($oWorkbook)
;~ Close the Excel Object
_Excel_Close($oExcel)

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By sksbir
      Hi
      Trying this from autoit v3.3.14.5 and SCITE 3.19.102.1901.0 :
      help file , page "Language Reference - Variables" , sample autoit script about maps:

      Maps must be declared before use by defining their scope using the 'Global/Local/Static' keywords. Local $mControls[]
      So is my test script : only with this local declation.
      -check syntax is OK
      - running script : 

      test.au3" (13) : ==> Variable subscript badly formatted.: Local $mControls[] Local $mControls[^ ERROR ->14:51:49 AutoIt3.exe ended.rc:1
      any clue ?
    • By 3Jake
      Hello Smart People!
      I have a multi-column .CSV that I would like to draw information from, in order to populate (send) that info to some fields in an Oracle form.  This would be for account-creation in Oracle.

      I have the basic script to navigate (tab) through the fields in the Oracle form, but I am SUPER-new to AutoIT and don’t quite see how to get the script to import and use variables from a .CSV

      For example:

      My script just waits for the page to be active, then enters data and tabs between fields like this:

      ; Wait for the window to be active WinWaitActive("Oracle is Cool - E-Business is the Best") ; User Name Send("jsmith") Send("{TAB}") ; Password Send("Password1") Send("{TAB}") Send("Password1") Send("{TAB}") ; Description Send("John Smith") Send("{TAB}") (etc. etc. etc.…)

      The winning solution would take one row at a time, feed it into fields on the Oracle form, save, and then start in on the next row

      It looks like I’d need a combination of “FileReadToArray” ( or“FileReadLine”?) and “StringSplit” to loop through the values and set them to variables, which would then replace my current "hard-coded" values to be typed them into the form?

      I found the following example in the “Help” snippets for stringsplit()… this seems like it’s in the ballpark but I’m having some trouble wrapping this around what I’ve put together, since each entry in the array would have multiple elements per line instead of just “Day”:

      Func Example() Local $aDays = StringSplit("Mon,Tues,Wed,Thur,Fri,Sat,Sun", ",") ;Split the string of days using the delimiter "," and the default flag value. #cs The array returned will contain the following values: $aDays[1] = "Mon" $aDays[2] = "Tues" $aDays[3] = "Wed" ... $aDays[7] = "Sun" #ce For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values. MsgBox($MB_SYSTEMMODAL, "", "$aDays[" & $i & "] - " & $aDays[$i]) Next EndFunc ;==>Example

      This post also seems like a similar example, but I don’t need it to be so selective RE: one specific column:
      https://www.autoitscript.com/forum/topic/166261-how-to-read-csv-specific-row-and-columns


      Any advice would be appreciated!  Thanks for taking a minute to look!  
    • By Blitzkid
      Hello, i want to search several directories for files with the largest numbers behind them (Like "video123") . They dont have a datatype. But there are also files with longer names and datatypes in these folders (Like "video778.mp4"). Is it possible to filter the _FileListToArray Syntax from
      to smth. like
       
      Here is my Code
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <File.au3> $filedir = @ScriptDir & "\" _checkfile() Func _checkfile() ConsoleWrite("______________________" & @CRLF) Local $arr[3] = ["music", "picture", "video"] For $i = 0 To UBound($arr) - 1 Local $arrayfiles = _FileListToArray($filedir & $arr[$i], $arr[$i] & "*", 1) If @error = 1 Then ConsoleWrite($arr[$i] & "Error 1") EndIf If @error = 4 Then ConsoleWrite($arr[$i] & "Error 2") ;Exit EndIf $arrayfilter = _ArrayMax($arrayfiles, 0, 1) Global $stringfiles = StringReplace($arrayfilter, $arr[$i], "") ConsoleWrite($arrayfilter & @CRLF) Next EndFunc ;==>_checkfile  
    • By jmp
      Script running good but error in line 7.
      When i run this script :
      #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData = _IETableWriteToArray ($oTable) For $inumber = 1 To UBound($aTableData) -1 $table = $aTableData[4][$inumber] MsgBox(0, "", $table) Next I got Error: array variable has incorrect number of subscripts or subscript dimension range exceeded
    • By nacerbaaziz
      Good morning guys, i hope that you're all well.
      guys, i have a problem and i hope that you can help me
      i've created an 3d array
      the array Contain a Categories info
      as folow
      $array[n][0][0] = Categorie name
      $array[n][0][1] = Categorie file path
      $array[n][0][2] = Categorie contents number
      $array[n][m][0] = link name
      $array[n][m][1] = link url
      $array[n][m][2] = link section name
      in my tool i want to add an option to delete a Category
      as you know the Categorie mean that must delete a region from the array
      when i tried to use _arrayDelete
      with the 2d array it work well
      but here i couldn't find any way to do that, can any one help me please?
      thanks in advance.
×
×
  • Create New...