[英]Powershell script not running on Task Scheduler
I have a PS script that opens Excel (Com Object), processes a bunch of information, re-saves, and then sends some critical information via e-mail.我有一个 PS 脚本,可以打开 Excel(Com Object),处理一堆信息,重新保存,然后通过电子邮件发送一些关键信息。 The script runs great, and when I run it from the Run Console, it works great as well.
该脚本运行良好,当我从运行控制台运行它时,它也运行良好。 However, when I schedule it as a task in the Task Scheduler it is not working properly.
但是,当我在 Task Scheduler 中将其安排为任务时,它无法正常工作。 The task seems to "successfully run" every single time, but I do not get the output e-mail that I am supposed to get.
该任务似乎每次都“成功运行”,但我没有收到我应该收到的输出电子邮件。 I have run many other PS Scripts without a problem using the same configuration in the task scheduler.
我在任务调度程序中使用相同的配置运行了许多其他 PS 脚本,没有问题。 Could this have something to do with opening Excel as part of a script scheduled?
这可能与将 Excel 作为预定脚本的一部分打开有关吗? Any thoughts are welcome.
欢迎任何想法。
I solved this issue using the answer from @briantist in PowerShell script won't execute as a Windows scheduled task , but I wanted to isolate exactly which switch was solving the problem.我在PowerShell 脚本中使用@briantist 的答案解决了这个问题, 不会作为 Windows 计划任务执行,但我想确切地隔离哪个开关正在解决问题。
It had nothing to do with -ExecutionPolicy
, -Noninteractive
, -NoLogo
, -NoProfile
or any other system privilege, user account running the script, etc.它与
-ExecutionPolicy
、 -Noninteractive
、 -NoLogo
、 -NoProfile
或任何其他系统权限、运行脚本的用户帐户等-NoProfile
。
Just needed to add -File
in front of the script path in the Task Scheduler > Actions > Arguments
field.只需要在
Task Scheduler > Actions > Arguments
字段中的脚本路径前面添加-File
。 Without this switch PowerShell was launching and the task history was showing Action Completed
, but the script was not executing.没有这个开关,PowerShell 正在启动,任务历史记录显示
Action Completed
,但脚本没有执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.