Monday, July 06, 2015

csv-loop snippet

 

This example reads from mycsv.csv in same folder as script is.
-----------------csv-loop.ps1------------------
#settings#
$myfilename = "mycsv.csv"

#settings end
$importfile = "$(split-path -Parent $myinvocation.MyCommand.Definition)\$myfilename"
import-csv $importfile -Delimiter "," |foreach-object {
#All things here will execute towards every line of $myfilename
write-host "$($_.fullpath) , $($_.site) , $($_.file)"
}
------------------eof-----------------------------

----------------mycsv.csv--------------------
fullpath,site,file
test1,test2,test3
test4,test5,test6
-------------------eof---------------------------

No comments: