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