I have a PowerShell script file that uses Invoke-RestMethod that downloads a dataset. When I run the script in PowerShell, it works just fine, however when I try to automate to run daily using Task Scheduler, it gets stuck in Running status and doesn’t download.
This is what the PowerShell script looks like (used x’s to replace confidential info):
$response = Invoke-RestMethod -Uri "x" `
-Method Post `
-ContentType "application/x-www-form-urlencoded" `
-Body "grant_type=client_credentials&client_id=x&audience=x"
$token = $response.access_token
$headers = @{
"accept" = "application/json"
"Authorization" = "Bearer $token"
}
$response = Invoke-RestMethod -Uri "x" -Headers $headers -OutFile "x.zip"
These are the settings I have in the Task Scheduler:
General
- Run whether user is logged on or not
- Run with highest privileges
Triggers
- Run daily at 9:00am
Actions
- Action : Start a program
- Program/script : C:WindowsSystem32WindowsPowerShellv1.0powershell.exe
- Add arguments : C:UsersxDesktopScriptsPowerShellx.ps1
Conditions
- Wake the computer to run this task
New contributor
tropicana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.