title: Executing PowerShell Script from Server Using PHP
body: <p>I have a PowerShell script hosted on a server. I am calling PowerShell script from Php as below:</p>
  <pre><code>&lt;?php
  header('Content-Type: text/plain');
  $csv = file_get_contents('http://domaincom/wp-content/uploads/csv-samples.csv');
  echo $csv;
  
  shell_exec('pwsh -File http://domaincom/wp-content/uploads/pscript.ps1');
  
  $psPath = &quot;powershell.exe&quot;;
  $psDIR = &quot;http://domaincom/wp-content/uploads/&quot;;
  $psScript = &quot;pscript.ps1&quot;;
  $runScript = $psDIR. $psScript;
  $runCMD = $psPath.&quot; &quot;.$runScript.&quot; 2&gt;&amp;1&quot;; 
  
  echo &quot;\$psPath  $psPath &lt;br&gt;&quot;;
  echo &quot;\$psDIR  $psDIR &lt;br&gt;&quot;;
  echo &quot;\$psScript  $psScript &lt;br&gt;&quot;;
  echo &quot;\$runScript  $runScript &lt;br&gt;&quot;;
  echo &quot;\$runCMD   $runCMD  &lt;br&gt;&quot;;
  
  exec( $runCMD,$out,$ret);
  
  echo &quot;&lt;pre&gt;&quot;;
  print_r($out);
  print_r($ret);
  echo &quot;&lt;/pre&gt;&quot;;
  ?&gt;
  </code></pre>
  <p>Script executes and I can see csv-samples.csv results in browser, but the powershell script doesn't execute. I get below message in browser:</p>
  <pre><code>Site,URL,Category
  Sitepoint,http://www.sitepoint.com/,Web development
  Html.it,http://www.html.it/,Web development
  Wamboo,http://www.wamboo.it/,Web development$psPath  powershell.exe &lt;br&gt;$psDIR  http://domaincom/wp- 
  content/uploads/ &lt;br&gt;$psScript  pscript.ps1 &lt;br&gt;$runScript  http://domaincom/wp- 
  content/uploads/pscript.ps1 &lt;br&gt;$runCMD   powershell.exe http://domaincom/wp- 
  content/uploads/pscript.ps1 2&gt;&amp;1  &lt;br&gt;&lt;pre&gt;Array
  (
      [0] =&gt; sh: 1: powershell.exe: not found
  )
  127&lt;/pre&gt;
  </code></pre>
  <p>Your help is very much appreciated.</p>
  <p>Thank You.</p>