Powershell计划任务冲突?
我已安排两个 powershell 脚本作为任务在 00:00 运行。
今天早上我检查了事件日志,发现其中一个脚本失败,出现以下异常:
失败。错误是:“未能 在以下位置创建日志条目: 'C:\Users\SPSETU~1\AppData\Local\Temp\PowerShellLog.txt'。 错误是:“该过程不能 访问文件 'C:\Users\SPsetupAdmin\AppData\Local\Temp\PowerShellLog.txt' 因为它正在被另一个人使用 过程.'.'.
- 问题可能与日志有关吗?两个脚本都使用 write-log 功能(请参阅 poshcode.txt )。 org)并使用相同的 id 登录 Windows 事件日志。
- 您知道作为计划任务的 powershell 脚本之间存在任何已知冲突吗?
- 我必须一次执行一个任务吗?
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:
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.’.'.
- 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,由于您同时尝试从两个不同的进程写入同一个文件,因此您可能会出现上述错误。
Powershell 与任何应用程序或程序具有相同的限制;在这种情况下文件写锁。我不认为 Powershell 脚本作为计划任务有任何“特殊”限制。
我要么确保您要执行的命令使用唯一的日志文件(如果同时运行它们是您的首要任务),要么将命令放在同一个脚本中并将其作为计划任务执行(如果将所有内容都放在一个日志中)你的首要任务)。
Well, since you simultaneously try to write to the same file from two different processes you can expect the above error.
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).
poshcode.org 代码记录到文件 PowerShellLog.txt 以及事件日志中,因此两个脚本都尝试写入同一文件。如果您只想写入事件日志,您可以尝试删除:
如果您想保留文件日志记录,那么我建议引入文件名作为参数。
The poshcode.org code logs to the file PowerShellLog.txt as well as the event-log so both of your scripts are trying to write to the same file. If you only want to write to the event-log you could try removing:
If you want to keep the file logging then I suggest the introduction of a file name as an argument.