Windows Task Scheduler is unable to launch a PowerShell script

Anonymous
2024-03-05T21:45:27+00:00

Hello

I am trying to run a Windows Task Scheduler...task to take a file and replace a SQL database nightly.

When I run the PowerShell script on it's own, it works flawlessly. Once I incorporate Windows Task Scheduler, it continuously fails. Either it'll run for a quick second and then go back to a Ready status with no errors in the History. Or it'll start, and sit at Run for over two hours and not do anything.

I have it to set to run with highest privileges, this is a Windows Server 2019, that is what the Configure it set for.

Program/script: powershell.exe

Add Arguments: Blank

Start In: C\Temp\Folder\Folder where .ps1 file exists

Keep in mind, if I run the script by itself, not in Task Scheduler, it works. I've tried adding the script path in Add Arguments, moved the script around, I am also logged in as Admin.

Stumped on this one. Thank you!

Windows for business Windows Server User experience PowerShell

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2024-03-06T07:18:19+00:00

    Hi Mark Bovenzi,

    Please add the full path of the script to "Add Arguments" and see if the script runs.

    0 comments No comments
  3. Anonymous
    2024-03-06T14:21:51+00:00

    When I do that, the Task will go to Running back to Ready, in the History logs, it says Task Completed Successfully. Last run results is a 0x1 which is the argument error.

    0 comments No comments
  4. Anonymous
    2024-03-06T19:20:59+00:00

    You will probably need to append the -ExecutionPolicy Bypass argument. You could also have such parameters stored in a batch file calling powershelll. Whether you use powershell or a batch file, you can always output the execution to a text file to see what is going on (>> or Out-File).

    0 comments No comments
  5. Anonymous
    2024-03-07T14:03:41+00:00

    I added the -ExecutionPolicy Bypass before the argument, same results. I tried -File, still the same.

    Unfortunately, I am not quite sure what you mean about execution output into a text file, apologies.

    0 comments No comments