Sign in to follow this  
Followers 0
gniuz

Read and split CSV per line

6 posts in this topic

#1 ·  Posted (edited)

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



#2 ·  Posted (edited)

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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

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

Maybe this can help with XML: XML DOM Wrapper


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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  
Followers 0