I am using PHP exec to run a Powershell script to create a new user that is being submitted via a HTML form. What I am looking to do is output only errors from this command on the webpage so any IT team member can see if anything went wrong. Here is what I have:
$psPath = 'c:\\Windows\\System32\WindowsPowerShell\v1.0\\powershell.exe -version 5';
$psDIR = "d:\\wamp64\\www\\includes\\";
$psScript = "NewHire.ps1";
$runCMD = $psPath. ' -ExecutionPolicy RemoteSigned '.$psDIR.$psScript
$createuser = exec($runCMD.' 2>&1', $out);
When I do a var_dump($out)
, it shows both the output and errors. I tried changing it to exec($runCMD.' &1', $out)
but it shows output only. If I try exec($runCMD.' 2>', $out)
, it doesn't run my command. Is there a way I can display errors only in the $out varible?