0

UPDATED CODE:

I have the following code. I wish to pass the InputTable to the nested script as a 2 dimensional string array, but I can't work out how to get this from the Get-Content (which appears to be a 1D array).

First Script:

$InputTablePath=C:\Temp\test.csv
$InputTable = Get-Content $InputTablePath
$scriptPath = 'C:\Temp\nested_script.csv

$m = Get-Content $tablePath
$rows = $m.count
$cols = ($m[0].split(",")).count

$InputTable = New-Object 'string[,]' $rows,$cols
for ($i=0;$i -lt $rows; $i++){
    for ($j=0;$j -lt $cols; $j++){
        $InputTable[$i,$j]= ($m[$i].split(","))[$j]
   }
}  


$argumentlist = "-InputTable '{0}'" -f $array

Invoke-Expression "& `"$scriptPath`" $argumentList" 

Nested Script:

Param(
    [string[,]]$InputTable
)

$numberOfRows = $InputTable.GetLength(0)
$numberOfColumns = $InputTable.GetLength(1)

etc....

I'm currently getting an index out of bounds error on the last line.

Many Thanks.

13
  • Well, Get-Content returns an array of strings, and I don't see you converting that in any way into a 2D array, so I'm not sure what how you expect that conversion to occur. It also looks like you're missing a " on line 4. Commented Jun 2, 2014 at 15:59
  • Agreed- I suppose the question is how to go about doing that. Commented Jun 2, 2014 at 16:00
  • Yes- I think using split might be the way forward but I'm not sure how. Commented Jun 2, 2014 at 16:03
  • You might also be interested in these two articles Use the Pipeline to Create Robust PowerShell Functions, about_Splatting. There's good advice there on making your functions pipeline friendly. Commented Jun 2, 2014 at 16:09
  • So I assume you are saying that the way to do this is to split each line and loop over all the lines? I.e. Something like: Get-Content $InputTablePath | Select -Skip 1 | ForEach-Object { $InputTable = $_.split(",") } Commented Jun 2, 2014 at 16:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.