Search code examples
powershellscheduled-taskstaskscheduler

Issue Running PowerShell on Windows Task Scheduler


I'm trying to run a PowerShell command via Task Scheduler but keep getting the below result when the task tries to run PowerShell on my Windows Server 2008 R2 environment.

action "powershell.exe" with return code 1.

When I run the script in PowerShell manually, the script runs. But for some reason, when I call it from the Task Scheduler it doesn't run.

A screenshot of how my action is set up is attached below.

I've made sure to do the following:

  1. Set ExecutionPolicy to RemoteSigned
  2. Set task to run with highest priveleges
  3. Set task to run whether user logged on or not
  4. Set task configuration for Windows 7, Windows Server 2008 R2

I'm fresh out of ideas.

enter image description here


Solution

  • Figured this one out thanks to some help from @TheIncorrigible1.

    The issue was that the Start In field on the task scheduler was set to a path with a root directory other than C:

    To resolve, I left Start In blank and in the Add Arguments field I called the script file with a full file path.

    Instead of the below in the Add Arguments field

    .\csv-convert.ps1
    

    I referenced the script as follows :

    D:\mypath\csv-convert.ps1
    

    Bottom line, dont start powershell in a path with a directory other than C: