在计划任务中的脚本参数中指定路径

时间:2016-02-04 09:34:43

标签: powershell

如果我创建一个计划任务,启动这样的Powershell脚本:

Powershell -command "& 'C:\test.ps1'"

如何在不中断-command参数的参数中输入路径参数?

Powershell -command "& 'C:\test.ps1 -path C:\Program Files(x86)\test'"

无效,因为找不到"C:\Program"

Powershell -command "& 'C:\test.ps1 -path 'C:\Program Files(x86)\test''"
or
Powershell -command "& 'C:\test.ps1 -path "C:\Program Files(x86)\test"'"

不起作用,因为包装路径的引号会中断-command参数

1 个答案:

答案 0 :(得分:1)

使用-File参数代替-Command

Powershell -File C:\script.ps1 -path C:\test