The Windows Task Scheduler can be used to run tasks at predefined intervals, e.g. once a day, and is very much like cron jobs found on other systems.
Running Powershell scripts requires some attention, or nothing will happen when the task scheduler launches it.
I wanted to fetch the contents of a web page every morning, in order to have the
data handy without having to do the work manually. So I decided not to use
for Windows, but instead rely on Powershell’s ability to call directly into .NET:
Running this shell script manually will prompt for the execution policy, in order
to make sure that I intend to execute the (possibly malicious) script. So scheduling
the execution of the script with the Task Scheduler will hang, as I won’t be there
[Y] to allow for the script to be run.
Starting a Powershell script, bypassing Execution Policy
The solution is to start
powershell.exe instead of the
*.ps1 script, and
-ExecutionPolicy argument in order to configure it to
powershell.exe -ExecutionPolicy Bypass C:\scripts\download-foo-bar.ps1