Powershell task from Scheduled Tasks keeps running forever

powershellscheduled-tasktask-scheduler

I've created an scheduled task to call a webpage using PowerShell, but I don't know why it is not going to be ended after execution, and the status remains "Running".

The action is "Start a program", with this parameter:

powershell -ExecutionPolicy unrestricted  -Command "(New-Object Net.WebClient).DownloadString(\"http://x.x.x.x/SomeUrl/\");"

Note that this task is configured to run by SYSTEM user, for being hidden while running.

Best Answer

To troubleshoot commands that are stuck under the system account I use PsExec

I would start an interactive system session like so:

PsExec.exe -s -i powershell.exe

And then try to execute the command.

Remember that when you run under the system environment in a scheduled task that you best use full paths to executables. So I would also replace powershell with C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Also make sure you set the "Start in" setting of your scheduled task when you trigger that command without defining a location.

Related Topic