Powershell Converting .csv format (Import-csv) to string -


i trying write powershell script

  1. read in csv file
  2. loop on each row in csv file.
  3. within each loop want pass csv header , row values script, both in system.string type format.

in particular, struggling conversion string type format- best way this. many thanks.

script 1:

$csvpath = 'c:\temp\scripts\trial_csv.csv' #get header $header = get-content $csvpath -totalcount 1 $intermediateoutput = "'c:\temp\scripts\output'" $scriptpath = 'c:\temp\scripts\temp.ps1'   #get data  get-content $csvpath | select -skip 1 | foreach-object {     $argumentlist = @()     $argumentlist += ("-header", $header)     $argumentlist += ("-row", $row)     $argumentlist += ("-intermediateoutput", $intermediateoutput)     $argumentlist += ("-index", $i )  invoke-expression "& `"$scriptpath`" $argumentlist" }  

script 2:

receive inputs script 1:

param(     [parameter(mandatory=$true)]      [string]$header, #the header of csv file     [parameter(mandatory=$true)]     [string]$row,  #the row of file, "1,0,2,.."     [parameter(mandatory=$true)]     [string]$intermediateoutput,  #intermediate directory     [parameter(mandatory=$true)]         [string]$index        #index      )  later (todo) $a = $header $b = $row $c = $intermediateoutput $d=$index 

if data in csv isn't quoted, should able use directly .csv file without need import-csv:

$csvpath = 'c:\temp\scripts\trial_csv.csv' $intermediateoutput = "'c:\temp\scripts\output'"  $index = 1  #get header $header = get-content $csvpath -totalcount 1  #get data  get-content $csvpath | select -skip 1 |  foreach-object {   $argumentlist = "-header '{0}' -row '{1}' -intermediateoutput {2} -index {3}" -f $header,$_,$intermediateoutput,$index    #execute script argument list    $index++   } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -