title: Powershell command in PHP
body: <p>I'm trying to be clever and create a form to create a VM in ESX.</p>
  
  <p>I have found the PowerCLI add-in for Poweshell and i have manually managed to create one.</p>
  
  <p>This is my code but I'm struggling to make it work.</p>
  
  <pre><code>{
  // Get the variables submitted by POST in order to pass them to the PowerShell script:
  $name = $_POST["name"];
  $diskmb = $_POST["diskmb"];
  $MemoryMB = $_POST["MemoryMB"];
  $NumCPU = $_POST["NumCPU"];
  $connectesx = "Connect-VIServer -Server IPADDRESS -Protocol https -User 'USERNAME' -password 'PASSWORD'";
  $createvm = "New-VM -Name $name -DiskMB $diskmb -MemoryMB $MemoryMB -NumCPU $NumCPU";
  $psScriptPath = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\esxdhb.psc1";
  
  // Execute the PowerShell script, passing the parameters:
      shell_exec("powershell -psc $psScriptPath -command $connectesx &amp;&amp; $createvm");
      echo ("$name Created Successfully.");
  </code></pre>