powershell - Cannot bind argument to parameter 'Path' because it is an empty array -
i use following code read data .csv. data read table converted normal variable can calculations.
$scriptpath = split-path $myinvocation.mycommand.path $transportoptions = $scriptpath + "\transportoptions.csv" $transportoptionsid = @() $transportoptions = @() $transportenergy = @() $co2 = @() import-csv $transportoptions |` foreach-object { $transportoptionsid += $_."transportoptionsid" $transportoptions += $_.transportoptions $transportenergy += $_.transportenergy $co2 += $_.co2 } $inputid = read-host -prompt "transportoptionsid" if ($transportoptionsid -contains $inputid) { $where = [array]::indexof($transportoptionsid, $inputid) $inputname = $transportoptions[$where] if ($transportoptions -contains $inputname) { $where = [array]::indexof($transportoptions, $inputname) $inputenergy = $transportenergy[$where] $htransportenergy = [double]$inputenergy if ($transportenergy -contains $inputenergy) { $where = [array]::indexof($transportenergy, $inputenergy) $co2transport = [double]$co2[$where] } } }
but got error:
error: import-csv : cannot bind argument parameter 'path' because empty array. error: co2estimatoruserinputs.ps1 (132, 11): error: @ line: 132 char: 11 error: + import-csv <<<< $transportoptions |` error: + categoryinfo : invaliddata: (:) [import-csv], parameterbindingvalidationexception error: + fullyqualifiederrorid : parameterargumentvalidationerroremptyarraynotallowed,microsoft.powershell.commands.importcsvcommand error:
do miss in code? idea solve error, please?
yes, missed something:
$transportoptions = $scriptpath + "\transportoptions.csv" $transportoptions = @() # import-csv $transportoptions |`
you assigned variable csv path, reassigned empty array before trying pass import-csv
.
Comments
Post a Comment