Until recently my PHP script calling a Powershell script with arguments was working fine, but now the string supposedly is in this format @("grp1","grp2")
on the Powershell side it is now grp1 grp2
The echo on PHP’s side before submission to Powershell is @("grp1","grp2")
The $_POST["groups"] is an array.
Here is my PHP code:
<?php
$ADJoinGroups = "C:ScriptsAD_Joingrps.ps1";
$entity = $_POST["entity"];
$fName = $_POST["fName"];
$lName = $_POST["lName"];
$desc = $_POST["description"];
$password = "#####";
$groups = '@("'.implode('","',$_POST["groups"]).'")';
echo '<pre>'; print_r($groups); echo '</pre>';
if (isset($_POST['cGrps'])) {
$res1 = shell_exec("powershell -InputFormat none -ExecutionPolicy ByPass -NoProfile -Command $ADJoinGroups $fName $lName $groups 2>&1");
echo $res1;
}
?>
The Powershell script looks as follows:
###### Args ######
$fName = $args[0];
$lName = $args[1];
$groups = $args[2];
Write-output $groups;
Does anyone know why this happens? And, do you have a way to revert it to @("grp1","grp2")
from grp1 grp2
in Powershell?
Many thanks 🙂
2
Answers
Thanks @Professor Abronsius you made me on the right path. Single quotes around my $groups made it
The test scripts I ran to emulate the original script with the difference of the
groups
portion of the commandline string being enclosed within double quotes and group names within single quotes.Powershell test script:
Output in browser: