1

Hy everybody, could someone explain to me why this happens?

$Script = {"My name is $($ARGS[0]) and my surname is $($ARGS[1])"} 



& $SCRIPT "CARL","WHITE" 

Output expected: MY name is CARL and my surname is WHITE

Actual output: My name is CARL WHITE and my surname is

that's because $args[0] is an array itself, this means that I should change the script like this:

$Script = {"My name is $($ARGS[0][0]) and my surname is $($ARGS[0][1])"} 

1 Answers1

3

It happens because you only provide 1 argument - an array consisting of the two string literals CARL and WHITE.

Remove the , and PowerShell will bind the two strings as two separate arguments instead:

& $Script "CARL" "WHITE" 
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206