【发布时间】:2020-01-29 09:09:01
【问题描述】:
我在 Task Scheduler Program/Script 提示符下调用 PowerShell 应用程序如下:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe
然后我在“添加参数”提示中调用可执行脚本,如下所示:
C:\1hwebster\PSISE_Scripts\OpenExcelFile.ps1
这成功地在 PowerShell 窗口中打开了我的脚本。但是,它不会运行脚本。
我还需要将一个参数从任务调度程序传递给脚本,为此我尝试了 -File 方法:
-文件 "C:\1hwebster\PSISE_Scripts\OpenExcelFile.ps1" fpathfname 'C:\1hwebster\VBA\DailyEconomicCalendar.xlsm'
这会将 fpathfname 参数作为第二个文件读取并批评我的语法。
我也试过-Command方法:
-Command "& C:\1hwebster\PSISE_Scripts\OpenExcelFile.ps1 -fpathfname 'C:\1hwebster\VBA\DailyEconomicCalendar.xlsm'"
我已经尝试了围绕 -File 和 -Command 内容的引号和单引号的所有迭代,但也没有成功。我需要输入什么才能成功运行 PowerShell 脚本并从任务计划程序传递参数?提前致谢。
【问题讨论】:
-
因为我只是想打开一个 Excel 文件,所以我绕过了 PowerShell,直接使用计划的 Excel 实例打开了该文件。如果有人有任何见解,我仍然想了解如何通过任务计划程序与 PowerShell 交互。
-
最好不要为此使用 ISE。使用 powershell.exe
-
发现弱点。重新写了答案。
标签: powershell scripting parameter-passing taskscheduler windows-task-scheduler