Calling API from task scheduler

From Logic Wiki
Jump to: navigation, search


Create a simple MyScriptName.ps1 file with the following contents:

$web = New-Object System.Net.WebClient
$str = $web.DownloadString("http://www.example.com/jobs/job1")
$str # not strictly necessary but if you run this in PowerShell you will get the response body of your endpoint

Then create a new scheduled task and add a new action to Start a program and use the following settings:

Program/script: powershell
Add arguments: .\MyScriptName.ps1
Start in: C:\The\Directory\You\Saved\Your\Script\In

to run powershell script it must be in this format other wise it opens notepad during run time

Powershell.exe -executionpolicy remotesigned -File  C:\Users\SE\Desktop\ps.ps1