Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Scheduled Tasks conflicts?

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?
like image 274
Emiliano Poggi Avatar asked Aug 05 '26 17:08

Emiliano Poggi


1 Answers

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).

like image 80
Torbjörn Bergstedt Avatar answered Aug 07 '26 19:08

Torbjörn Bergstedt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!