powershell - Cannot bind argument to parameter 'Path' because it is an empty array -


this .csv file: enter image description here

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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -