Powershell – Task scheduler / powershell / timeout

powershellscheduled-tasks

I have a website which I need to run a script every hour. I set these parameters on task scheduler and it seems to work.

Program/script: powershell.exe

Add arguments: -c (new-object system.net.webclient).downloadstring('http://www.example.com/test.ashx')

The problem is that I have a big loop and processes in this script and the script stops before it finish the loop! Is there any possibility to add a timeout as an argument or something else to prevent this?

I'm using Windows Server 2008R2 and .NET 4

Best Answer

PowerShell won't terminate a script early because of a timeout - so that isn't the problem. The most likely causes are that something in your script is raising an exception or possibly the Task Scheduler is configured to kill a task that runs too long. Either way, you can probably find the information to diagnose that in the event log or the task scheduler log.

An easy place to check is the task properties you have created. On the Settings tab there is an option to "stop the task if it runs longer than" - you might have that enabled and set to 1 hour.

Task Scheduler Settings