PowerShell add Task to run PowerShell script with parameters
问题 I am trying add a Task to the Task Scheduler from a PowerShell script that will run a PowerShell script with parameters. 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. $command = "PowerShell \`"& 'C:\ProgramFiles (x86)\MyDir\MyScript.ps1' $myStringParam $myBooleanParam\'"" Write-Host $command # This outputs: PowerShell \"& 'C:\Program Files (x86)\MyDir\MyScript.ps1' Cat 0\"