title: Can't run powershell script from php
body: <p>I use the Powershell script following to get a <code>show run</code> command run on a cisco device :</p>
  
  <p><strong>getconfig.ps1</strong></p>
  
  <pre><code>$ErrorActionPreference ="Inquire"
  Import-Module SSH-Sessions
  $time ="$(get-date -f yyyy-MM-dd)"
  $filename ="config"
  $ext =".txt"
  $filepath ="temp\"
  $d1 ="x.x.x.x"
  $u1 ="user"
  $p1 ="password"
  New-SshSession $d1 -Username $u1 -Password "$p1"
  $c1 ="show run"
  $Results = Invoke-Sshcommand -InvokeOnAll -Command "$c1" | Out-File "$filepath$filename-$time$ext"
  Remove-SshSession -RemoveAll
  exit
  </code></pre>
  
  <p>When I run this script manually by right click/run with powershell that's worlking fine. The problem come when I try to run this script via PHP.</p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>&lt;?php
  $output = shell_exec('powershell C:\wamp\www\getconf\script\getconfig.ps1');
  echo "&lt;pre&gt;$output&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>index.php loads forever and never give me an output and never create the results file.</p>
  
  <p>I have tried to run another script, like <strong>test.ps1</strong> that simply create a directory and it's working fine; I get the output and my directory is created.</p>
  
  <p>My powershell script works.</p>
  
  <p>The link between PHP and my PowerShell script works.</p>
  
  <p>I do not understand where is the problem from.</p>