[英]Windows Task Scheduler — Fails to run Powershell Scripts
I have written two powershell scripts that I need to run every morning. 我已经编写了两个Powershell脚本,每个脚本都需要每天早晨运行。 The first generates a text file of the names and location of all of the new files added to a directory within the last twenty-four hours.
第一个生成的文本文件包含最近二十四小时内添加到目录中的所有新文件的名称和位置。 The second script that I wrote takes that .txt file and e-mails it to myself.
我编写的第二个脚本接收该.txt文件并将其通过电子邮件发送给我自己。
Both of these scripts run perfectly when executed manually. 当手动执行时,这两个脚本都能完美运行。 I added them both to the task scheduler but the scheduler does not properly execute the scripts.
我将它们都添加到任务计划程序中,但是计划程序无法正确执行脚本。 The text file does not get generated, and the e-mail does not get sent.
不会生成文本文件,也不会发送电子邮件。
Things that I have done (for both scripts): 我已经完成的事情(对于两个脚本):
ExecutionPolicy
is Unrestricted
. ExecutionPolicy
是否Unrestricted
。 Edit: Since that picture is so small here is a direct link: http://imgur.com/EX7Vxj7 编辑:由于图片太小,这里是直接链接: http : //imgur.com/EX7Vxj7
The Action needs to be set to "Start a program" and the program should be PowerShell.exe
该操作需要设置为“启动程序”,并且该程序应为
PowerShell.exe
Secondly in the Add Arguments box you need to enter -File '[script path]'
. 其次,在“添加参数”框中,需要输入
-File '[script path]'
。 You can add -NoExit
if you want to keep the window open afterwards but it will need to be running as your own user of course. 如果要在以后使窗口保持打开状态,则可以添加
-NoExit
,但是它当然需要以您自己的用户身份运行。
If your script is located on a shared map you need to provide unc to the file like this: 如果您的脚本位于共享地图上,则需要向文件提供unc,如下所示:
\\servername\script.ps1
You can find more details in this post: https://dmitrysotnikov.wordpress.com/2011/02/03/how-to-schedule-a-powershell-script/ 您可以在这篇文章中找到更多详细信息: https : //dmitrysotnikov.wordpress.com/2011/02/03/how-to-schedule-a-powershell-script/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.