Trying to run the following command in php to run powershell command...
the following works:
$output = shell_exec(escapeshellcmd('powershell get-service | group-object'));
I can not run it like this:
$output = shell_exec('powershell get-service | group-object');
it will not pass the pipe | character
but if I try to run:
$output = shell_exec(escapeshellcmd('powershell get-service | where-object {$_.status -eq "Running"}'));
I get no output.
The following:
$cmd = escapeshellcmd('powershell get-service | where-object {$_.status -eq "Running"}');
returns:
powershell get-service ^| where-object ^{^$_.status -eq ^"Running^"^}
Any suggestions on why this is happening and how to fix this?
Edit: Also I could run it as .ps1 script but I want to be able to pass $var to it.