简体   繁体   English

Windows Task Scheduler —无法运行Powershell脚本

[英]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): 我已经完成的事情(对于两个脚本):

  1. Selected the option to run whether user is logged on or not. 选择了无论用户是否登录都运行的选项。
  2. Set to run with the highest privleges 设置为以最高特权运行
  3. Have checked and rechecked that my 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.

相关问题 Powershell 新对象在 Windows 任务调度程序运行时失败 - Powershell New-Object fails when run by Windows Task scheduler Windows Server 2012 R2 - Powershell 脚本 - 以管理员身份运行 - 在任务计划程序中失败发生约束冲突 - Windows Server 2012 R2 - Powershell script -Run as Admin - fails in Task Scheduler A constraint violation occurred 由任务调度程序运行时,Powershell 脚本无法正常工作 - Powershell scripts not working properly when run by task scheduler Excel 宏通过 powershell 运行,但在 Windows 任务计划程序运行时不运行 - Excel macros run through powershell but not when run by windows task scheduler 通过任务计划程序运行时,Azure Powershell脚本失败 - Azure Powershell script fails when run through task scheduler 通过任务计划程序运行时,导航PowerShell脚本失败 - Navigation powershell script fails when run through task scheduler VBScript 不会从从 Windows 任务计划程序运行的 Powershell 脚本中运行 - VBScript will not run from Powershell script that runs from Windows Task Scheduler powershell 查询 windows 任务调度程序,用于将在特定日期时间之间运行的任务 - powershell query windows task scheduler for tasks that will run between specific datetimes 任务调度程序 powershell 脚本永远不会结束 - task scheduler powershell scripts never ends 任务计划未执行可通过任务计划程序(Windows10)手动运行的Powershell脚本 - Task Scheduling not executing a Powershell script that can be manually run through Task Scheduler (Windows10)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM