Jump to content
Sign in to follow this  
gniuz

Read and split CSV per line

Recommended Posts

gniuz

Hi,

I'm new to AutoIt and have been focussing on Powershell instead. However, there's a need to accomplish something that I (even with the help of the WASP PSSnapin) can't get to work.

Can anyone please provide me an autoit translation of the following powershell script? It basically just reads a csv and splits it per line. I've found some references on this forum but they don't seem to read and split the stuff per line. Many thanks!

Input.csv:

----------

username, oldpw, newpw

jimbo, seed, homebrew

treehugginghippie, green, leaf

terminatorx, bass, howlowcanyougo

powershell.ps1:

---------------

$csv_file = $env:systemdrive+'\input.csv'

$csv_info = Import-Csv $csv_file

foreach ($line in $csv_info) {

& bla.exe -username $($line.username) -oldpw $($line.oldpw) -newpw $($line.newpw)

}

Edited by gniuz

Share this post


Link to post
Share on other sites
Baraoic

I don't know powershell but if you wanna read a multilined file and split it per line you could do _FileReadToArray. It would read that text document and put each line into a cell in the array then you could do whatever you wanted with it from there.

Edited by Onichan

Share this post


Link to post
Share on other sites
water

Something like:

#include <file.au3>
_FileReadToArray("filename",$aArray)
For $iCount = 1 To $aArray[0]
    $aFields = StringSplit($aArray[$iCount],",")
    ShellExecuteWait("bla.exe","-username " & $aFields[1] & " -oldpw " & $aFields[2] & " -newpw " & $aFields[3])
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
gniuz

Something like:

#include <file.au3>
_FileReadToArray("filename",$aArray)
For $iCount = 1 To $aArray[0]
    $aFields = StringSplit($aArray[$iCount],",")
    ShellExecuteWait("bla.exe","-username " & $aFields[1] & " -oldpw " & $aFields[2] & " -newpw " & $aFields[3])
Next

Wow guys, thanks for the extremely quick reply. I'll start experimenting right away and let you know. Tnx!

Share this post


Link to post
Share on other sites
gniuz

That went great.. Now here's something else.

What if the CSV file would be an XML file. How would this change the script?

input.xml:

----------

<UserList>
            <User>
                <Name>jimbo</Name>
                <OldPW>seed</OldPW>
                <NewPW>homebrew</NewPW>
            </User>
            <User>
                <Name>treehugginghippie</Name>
                <OldPW>green</OldPW>
                <NewPW>leaf</NewPW>
            </User>
            <User>
                <Name>terminatorx</Name>
                <OldPW>bass</OldPW>
                <NewPW>howlowcanyougo</NewPW>
            </User>

</UserList>

Once again, thanks for your time!

Share this post


Link to post
Share on other sites
water

Maybe this can help with XML: XML DOM Wrapper


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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
Sign in to follow this  

×