Friday, October 13, 2023

HOW TO - Curl from Task Scheduler in Windows

q: A customer requested to run a curl command on a regular schedule from a windows computer.

a: Within Windows, create a Scheduled Task that runs as system, using Powershell and Invoke-WebRequest

General tab: Use the following user account: SYSTEM
Trigger tab: At system startup - After triggered, repeat every 5min
Action tab: Start a program - C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 
Add Arguments:  "Invoke-WebRequest -uri '""' -usebasicparsing"

a) running an invoke-webrequest as system fails without the trailing switch -usebasicparsing
b) we ended up putting the entire argument within double quotes and then the URL nested within double quotes inside single quotes - single quote, double quote, URL, double quote, single quote.

No comments:

Post a Comment