I do see a strange behavior when running PowerShell scripts triggered by Windows Task Scheduler.
So that's my setup: Win2016 Task in Task Scheduler:
- Action: Run powershell.exe with Arguments: "\Path\to\my\Script.ps1"
- Run whether user is logged in or not
- Run with highest privileges
- Trigger: Run every Friday
The Script.ps1 actually starts a couple of other PowerShell scripts with Start-Process.
Now …
Behavior 1: When I start the task by myself by clicking "Run task" within the Task Scheduler, the script.ps1 runs just fine, starts all the sub-scripts that all run fine as well.
Behavior 2: I wait for the task to run by itself on Friday. The scripts.ps1 runs fine, starts all the sub-scripts and the task finishes fine. But the sub-scripts they just hang. I see them in the task manager, all with a couple of memory allocated (Like 14MB that does not change), but they do nothing. Its like they are started but do not run the first line of the script. Even more strange is, that some of the sub-scripts run just fine, like 2 out of 10, but the other 8 just stuck forever.
What is going on here?