title: executing a Powershell script from php
body: <p>I'm trying to execute a powershell script from PHP, but it does not seem to work.</p>
  
  <p>The script 'newEvent.ps1' creates an event on the Exchange server.</p>
  
  <pre><code>$psPath = "powershell.exe";
  $psDIR = "C:\\wamp\\www\\ant\\assets\\ps\\";
  $psScript = "newEvent.ps1";
  $runScript = $psDIR. $psScript;
  $runCMD = $psPath." ".$runScript." 2&gt;&amp;1"; 
  
  echo "\$psPath  $psPath &lt;br&gt;";
  echo "\$psDIR  $psDIR &lt;br&gt;";
  echo "\$psScript  $psScript &lt;br&gt;";
  echo "\$runScript  $runScript &lt;br&gt;";
  echo "\$runCMD   $runCMD  &lt;br&gt;";
  
  exec( $runCMD,$out,$ret);
  
  echo "&lt;pre&gt;";
  print_r($out);
  print_r($ret);
  echo "&lt;/pre&gt;";
  </code></pre>
  
  <p>It outputs:</p>
  
  <pre><code>$psPath powershell.exe
  $psDIR C:\wamp\www\ant\assets\ps\
  $psScript newEvent.ps1
  $runScript C:\wamp\www\ant\assets\ps\newEvent.ps1
  $runCMD powershell.exe C:\wamp\www\ant\assets\ps\newEvent.ps1 2&gt;&amp;1
  
  Array
  (
      [0] =&gt; File C:\wamp\www\ant\assets\ps\newEvent.ps1 cannot be loaded because the execut
      [1] =&gt; ion of scripts is disabled on this system. Please see "get-help about_signing"
      [2] =&gt; for more details.
      [3] =&gt; At line:1 char:39
      [4] =&gt; + C:\wamp\www\ant\assets\ps\newEvent.ps1 &lt;&lt;&lt;&lt;
      [5] =&gt;     + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
      [6] =&gt;     + FullyQualifiedErrorId : RuntimeException
      [7] =&gt; 
  )
  </code></pre>
  
  <p>If I run <code>powershell.exe C:\wamp\www\ant\assets\ps\newEvent.ps1</code> on the command-line, it works fine.</p>
  
  <p>This is the first time im attempting something like this. I ran <code>Set-ExecutionPolicy RemoteSigned -Scope LocalMachine</code> but it still gives me the same error.
  In fact I ran <code>Set-ExecutionPolicy unristricted</code>, but it's still the same.</p>