Jump to content

How to read PowerShell command into a multiple dimensional dimensional array? - (Moved)

Recommended Posts

$sCommands1 = 'powershell.exe Get-ChildItem'
$iPid = run($sCommands1   , @WorkingDir , @SW_SHOW , 0x2)

$sOutput = ""

 While 1
    $sOutput &= StdoutRead($iPID)
        If @error Then

;~ msgbox(0, '' , $sOutput)
$aOutput = stringsplit($sOutput ,@LF , 2)

For $i=0 To  UBound($aOutput) - 1 Step 1


The script above reads the whole directory into a one dimensional array, but I need to work with the array, so I need to split the array into multiple dimensions.

I have already read some forum answers here, and I have already tried these commands:




_ArrayAdd($aOut , _ArrayToString($aOutput) , 0 , " " @CRLF"|" , 1)



Are there any way to use the $aOutput variable like in PowerShell:


$a = Get-ChildItem


I imagine this in AutoIt  $aOutput


Or if I split this command into 2 dimension like:

For $i To UBound($aOutput)-1 Step 1





Edited by DannyJ
Link to post
Share on other sites

in my much acclaimed* post titled: 

there is an example of chopping into 2 dimensional array. Maybe that can be of help ?.

Developer General Discussion, is for AutoIt development as a product, not general help scripting.

*much acclaimed may be an exaggeration from the over imaginative author 

Link to post
Share on other sites
#include <Array.au3>
Func _HowToChopSuey()
    Local $sCommands1 = 'powershell.exe Get-ChildItem'
    Local $ArrayB, $sOutput = "", $iPid = run($sCommands1   , @WorkingDir , @SW_SHOW , 0x2)

    While 1
        $sOutput &= StdoutRead($iPID)
        If @error Then ExitLoop

    $aOutput = stringsplit(StringReplace($sOutput, @CR, "") ,@LF , 2)
    Local $aReturn[UBound($aOutput)][6]

    For $i=0 To UBound($aOutput) - 1 ; Step 1
        ConsoleWrite($i & @TAB & $aOutput[$i] & @CRLF)
        $aReturn[$i][0] = $i ; or not, no clue
        $aReturn[$i][1] = StringMid($aOutput[$i], 1, 7)
        $aReturn[$i][2] = StringMid($aOutput[$i], 14, 11)
        $aReturn[$i][3] = StringMid($aOutput[$i], 26, 11)
        $aReturn[$i][4] = StringMid($aOutput[$i], 36, 14)
        $aReturn[$i][5] = StringMid($aOutput[$i], 51)
Return $aReturn


Link to post
Share on other sites
  • Developers

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:


General development and scripting discussions.

Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bogQ
      Simple script latest autoit version.
      #include <GUIConstantsEx.au3> #include <FontConstants.au3> Example() Func Example() GUICreate("test", 800, 540) GUISetFont(12, $FW_NORMAL, $GUI_FONTNORMAL) GUICtrlCreateLabel("testing",680,310) GUISetState(@SW_SHOW) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example After using GUISetFont(12) or GUISetFont(12, $FW_NORMAL, $GUI_FONTNORMAL) every GUI control is changed to italic.
      Am i doing something wrong?

    • By woffi
      I'm afraid I'm just stupid or blind or both: how can I read user input from an AutoIt console program? Just a simple String input, terminated with pressing "Return"? 

      This can't be difficult, but I can't find a solution.
    • By TheAlienDoctor
      Hi, I was looking into creating a script that would detect if a file exists, then move it (and in some cases rename it, depending on the file) as well as write to a log file.
      The issue is, there is a lot of files that need to be moved, sometimes some files will exist and others won't depending on the use-case. However if a file does exist, it will always be going into the same directory with the same name.
      Currently I have an array nested inside of the array, with each array inside that array having both the old and new directory, and then a For loop to actually run through and do the file transferring. The issue I am having is how to call the Array inside of the array, because how do I specify  which the old directory is and which the new is?
      Global $FileTransfer[2000] = [Global $Dir1[2] = ["original dir 1", "new dir 1"], Global $Dir2[2] = ["original dir 2", "new dir 2"]] For $FileTransfer = [0] To [1] Step +1 If FileExists({original dir}) Then FileMove({original dir}, new dir, 1) FileOpen("log.latest.txt", 1) FileWrite("log.latest.txt", "{original dir} found, moved it to new dir." & @CRLF) FileClose("log.latest.txt") Else FileOpen("log_latest.txt", 1) FileWrite("log_latest.txt", "{original dir} not found, ignoreing it." & @CRLF) FileClose("log_latest.txt") EndIf Next I have put what I want the old and new directory to be for each array in {}, so hopefully its easier to tell which part is working and whats not.

      I am still reasonably new to AutoIT, any help is appreciated. Thankyou
    • By arunkw
      I have a spreadsheet - daily routine which has two columns: activity and time as shown here
      | Activity             | Time     | |----------------------|----------| | Sleep               |  6:00 am | | Toilet              |  6:15 am | | Get ready for gym  |  6:30 am | | Exercise            |  7:50 am | | ... more things      |  9:00 pm | | ... still more       | 10:45 pm | | Sleep               |  6:00 am |   I wanted to find out, say in C1 which activity is current for me using now() I.e., if it’s 6:45am on my watch, it should show me Exercise  in C1 Thanks to Adam D. PE, this formula works like magic to get the result =VLOOKUP(MOD(NOW(),1),{B2:B,A2:A},2,1)   Now, I want to reproduce same result in autoit, how to do that? To have easy solution say, I copy-paste spreadsheet data in array directly in code, right? Use for loop and run the above vlookup function and show the answer using tooltip. How to achieve this? please help.  
    • By goku200
      I have an Autoit script that lists files from a folder into an array list. Is there a way to separate the filenames by an underscore and include the id, version, name and date into separate columns in Excel.
      Example of filename:
      12345_v1.0_TEST Name [12345]_01.01.2022.html
      12345 would be in one column
      v1.0 would be in another column
      TEST Name [12345] would be in another column
      01.01.2022 would be in another column
      .html would be in another column
      Note: filenames always change each day.
      Here is my code that lists the files into column C and then writes the column Headers into Column D, E, F, G. Just need some help with separating them into columns by the _ delimiter
  • Create New...