11

I have an MVC app. I have a controller that when called runs a background process to query Active Directory and updates the database.

http://myapp/BackgroundTask/Run

I want to run this on a schedule (daily) without opening a browser. I see that there's a lot of third party solutions, is there something built in?

Jack
  • 497
  • 3
  • 5
  • 11

2 Answers2

26

Use the Invoke-WebRequest cmdlet from Powershell.

In your task:

  • Action: Start a program
  • Program/script: powershell.exe
  • Arguments: -Command "Invoke-WebRequest http://myapp/BackgroundTask/Run"
Ryan Bolger
  • 16,472
  • 3
  • 40
  • 59
  • 1
    How to use Integrated Authentication? – Jack Jan 31 '17 at 17:15
  • Note: this only works in PowerShell 3 and up (to check your version, type `get-host` in powershell). In lower versions you'll need to call a separate powershell script, like in https://stackoverflow.com/questions/17486205/call-an-url-with-scheduled-powershell-script – DdW Sep 27 '17 at 06:27
0

Alternatively, you can use cmd.exe as follows:

  • Action: Start a program
  • Program/script: cmd.exe
  • Arguments: /c start "" http://myapp/BackgroundTask/Run &
Stephen Quan
  • 161
  • 1
  • 4