0

As usual with coding I realize this is probably some obvious thing that I just can't see but I have this function in powershell that is accepting my input as a single array instead of three separate variables and I can't figure out how to fix it.

function Breakfast($itemOne, $itemTwo, $itemThree) {
    "For breakfast I want $itemOne, $itemTwo, and $itemThree"
}

Breakfast("eggs", "bacon", "milk")
Breakfast("milk", "cereal", "yogurt") 
Breakfast("yogurt", "granola", "fruit") 

The output I'm getting is this:

For breakfast I want eggs bacon milk, , and

For breakfast I want milk cereal yogurt, , and

For breakfast I want yogurt granola fruit, , and

In advance, thank you all.

jumper
  • 83
  • 4
  • 5
    Remove the brackets around the parameters and also the commas. PowerShell uses spaces to separate parameters. So `Breakfast "eggs" "bacon" "milk"` – Theo May 07 '20 at 17:10
  • 1
    as `Theo` pointed out, you need to remove the `()` parens around the parameter values you are feeding to your function. ///// this demos one reason why one otta avoid using the simplified function definition. [*grin*] it _implies that you call a fun via >>> `Do-Stuff ($Var1, $Var2, $Var3)` <<< however, that will send all your values in as a one item - an ARRAY of 3 items - that will go to the 1st parameter, not as 3 items with one for each parameter. – Lee_Dailey May 07 '20 at 17:46

0 Answers0