The reason this is happening is that you're expanding an array, $Tasks
, inside a double-quoted string. Before your command line is passed to PowerShell.exe, it is expanded to:
Arg 0 is <& {. C:\Script2.ps1 -BuildNum ; Run-Validation -Tasks Task1 - Name1 Task2 - Name2 Task3 - Name3}>
So the Run-Validation -Tasks
parameter only sees "Task1". If you were to look at $args inside of the Run-Validation function you would see the rest of the arguments.
BTW, why invoke another Powershell.exe session? Why not just invoke like so:
. $PSScriptRoot\Script2.ps1 -BuildNum $BuildNum
Run-Validation -Tasks $Tasks
Note that the above only works if you eliminate the script level $Tasks parameter in Script2.ps1. If not, when you dot source Script2.ps1 to gain access to the Run-Validation function, the $Tasks in Script2.ps1 effectively overwrites the value set in Script1.ps1.
If you really want to invoke this in a separate PowerShell session you can do this:
$OFS="','"
powershell "& {. $pwd\Script2.ps1 -BuildNum $BuildNum; Run-Validation -Tasks '$Tasks'}"