Powershell计划任务有冲突吗? [英] Powershell Scheduled Tasks conflicts?

查看:68
本文介绍了Powershell计划任务有冲突吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安排了两个Powershell脚本作为要在00:00运行的任务.

I have scheduled two powershell scripts as tasks to run at 00:00.

今天早上,我检查了事件日志,发现其中一个脚本失败,但出现以下异常:

This morning I checked the event log and found that one of the scripts failed with the following exception:

失败.错误是:未能 在以下位置创建日志条目: ‘C:\ Users \ SPSETU〜1 \ AppData \ Local \ Temp \ PowerShellLog.txt". 错误是:‘该过程无法 存取档案 'C:\ Users \ SPsetupAdmin \ AppData \ Local \ Temp \ PowerShellLog.txt' 因为它被另一个人使用 过程.’.

Failure. The error was: 'Failed to create log entry in: ‘C:\Users\SPSETU~1\AppData\Local\Temp\PowerShellLog.txt’. The error was: ‘The process cannot access the file 'C:\Users\SPsetupAdmin\AppData\Local\Temp\PowerShellLog.txt' because it is being used by another process.’.'.

  • 可能是与日志有关的问题吗?这两个脚本都使用写日志功能(请参见 poshcode.org ),然后使用相同的ID登录Windows事件日志.
  • 您知道Powershell脚本之间作为计划任务的任何已知冲突吗?
  • 我必须一次执行一次任务吗?
    • Can be the problem related to logs? Both the scripts are using the write-log function (see poshcode.org) and log in the windows event log with the same id.
    • Do you know any known conflict among powershell scripts as scheduled tasks?
    • Do I have to execute tasks one a time?
    • 推荐答案

      好吧,由于您同时尝试从两个不同的进程写入同一文件,因此您可能会遇到上述错误.

      Well, since you simultaneously try to write to the same file from two different processes you can expect the above error.

      Powershell与任何应用程序或程序都有相同的限制;在这种情况下,文件写锁定.我认为对Powershell脚本作为计划任务没有任何特殊"限制.

      Powershell has the same restrictions as any application or program; in this case file write-locks. I don't think there are any "special" restrictions on Powershell scripts as scheduled tasks.

      我要么希望您要执行的命令使用唯一的日志文件(如果同时运行它们是您的头等大事),要么将命令放在同一脚本中并作为计划任务执行(如果获取所有内容)一本日志是您的头等大事.

      I would either see to that the commands you want to execute uses unique log files (if running them simultaneously is your top priority), or put the commands in the same script and execute this as a scheduled task (if getting everything in one log is your top priority).

      这篇关于Powershell计划任务有冲突吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆