title: PowerShell add Task to run PowerShell script with parameters
body: <p>I am trying add a Task to the Task Scheduler from a PowerShell script that will run a PowerShell script with parameters. </p>
  
  <p>The spaces in the file path are conflicting with the necessary quotes surrounding the whole command, and SCHTASKS converts ' to " so I can't encapsulate properly.</p>
  
  <pre><code>$command = "PowerShell \`"&amp; 'C:\ProgramFiles (x86)\MyDir\MyScript.ps1' $myStringParam $myBooleanParam\'"" 
  Write-Host $command # This outputs: PowerShell \"&amp; 'C:\Program Files (x86)\MyDir\MyScript.ps1' Cat 0\"  
  SCHTASKS /Create /TN "MyTask" /TR "$command" /SC DAILY /ST 01:30:00 /RL Highest /EC ScriptEvents /RU SYSTEM
  </code></pre>
  
  <p>but Task Scheduler shows Actions as:</p>
  
  <pre><code>PowerShell "&amp; "C:\Program Files (x86)\MyDir\MyScript.ps1" Cat 0"
  </code></pre>
  
  <p>The " and " cancel each other out because ' is always switched to " here, thus task fails.</p>