I am trying to transport a PHP array (from index.php) to a Powershell function (ps_scripts.ps1) as an argument. However, am getting an error(error below). I am using the EXEC function in PHP to pass arguments to the Powershell function.
PHP Code:
$psPath = "powershell.exe -InputFormat none -ExecutionPolicy ByPass -NoProfile ";
$psDIR = "C:\\xampp\\htdocs\\";
$psScript = "ps_scripts.ps1";
$runScript = $psDIR. $psScript;
$runCMD = $psPath." ".$runScript." 2>&1 ";
$parameter_2 = "testdata";
$array = array("Peter"=>24, "Ben"=>"Hello");
$encoded_data = json_encode($array);
exec($runCMD . "example_function_name \"" . $encoded_data . "\"" . " \"" . $parameter_2 . "\"", $output, $retval);
Powershell Code - ps_scripts.ps1:
$arguments = $args;
function example_function_name
{
$sData = $arguments[0] | ConvertFrom-Json
echo $sData;
}
Error:
Array ( [0] => At line:1 char:70 [1] => + ... htdocs\ps_scripts.ps1 example_function_name {Peter:24,Ben:Hell ... [2] => + ~ [3] => Missing argument in parameter list. [4] => + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException [5] => + FullyQualifiedErrorId : MissingArgument [6] => ) 1