title: Executing powershell script from PHP with arguments
body: <p>I have been wracking my brain and my pc on this one, hoping someone can help me out here.</p>
  
  <p>I have a PHP site that needs to execute a powershell script which in turn executes  and executable.</p>
  
  <p>the PHP that calls the .ps1 is</p>
  
  <pre><code>define('updaterPath','C:\\artemis\\DbUpdateUtility1.0.12.2');
  define('outputLocation',updaterPath.'\\Output');
  $CMD = updaterPath . '\\ArtemisXmlUtil.exe';
  $action = 'import';
  $args= ' -f' . outputLocation;
  $psScriptPath = '.\\get-process.ps1';
  $query = shell_exec("powershell -command $psScriptPath -cmd '$CMD' -action '$action' -paras '$args' &lt; NUL");
  </code></pre>
  
  <p>my .ps1 script is:</p>
  
  <pre><code>param(
  [string]$CMD,
  [string]$action,
  [string]$paras
  )
  
  &amp; $CMD $action $paras
  </code></pre>
  
  <p>Right now, when I echo the full command, it looks perfect and can be copied and pasted into powershell and runs successfully, but when I try to actually execute it from php, it runs with only the $CMD variable and ignores the $action and $paras.</p>
  
  <p>I tried concactenating the variables all into 1 string, but that fails as not even being able to see the executable.</p>
  
  <p>the full command shouls look like:</p>
  
  <pre><code>C:\artemis\DbUpdateUtility1.0.12.2\ArtemisXmlUtil.exe import -fC:\artemis\DbUpdateUtility1.0.12.2\Output
  </code></pre>