Powershell Version 4脚本执行此操作:它从网页获取下载链接,下载,文件并将其保存到动态创建的目录中 . 该脚本运行正常 - 从命令行或Windows计划任务启动 .

以下是计划任务设置:

Program Script:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add Arguments:
-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -File "R:\powershell_scripts\downloadscript.ps1"

Start In:
R:\powershell_scripts\

我'd like to create a Scheduled Job from Powershell to create and manage the task as a Powershell Job. I am able to do this as follows, problem is, the job (which shows up in as it should as a Windows Task) doesn'工作 . 它运行没有错误,但脚本不执行其功能 . 我无法弄清楚如何让Powershell作业脚本将参数(如 -ExecutionPolicy Bypass )传递给任务 - 或者弄清楚问题是什么 .

这是我尝试的方式:

#Trigger
$weeklywednesday = New-JobTrigger -Weekly -DaysOfWeek Tuesday -At 17:00

#Script
$scriptPath = "R:\powershell_scripts\downloadscript.ps1"

Register-ScheduledJob -Name DownloadMyWebFile -FilePath $scriptPath -Trigger $weeklywednesday

有没有人知道为什么我无法让一个脚本从预定作业运行,因为它在Windows中的任务计划程序中创建的工作正常?谢谢 .