4

I have a PowerShell script set to run daily as a scheduled task, it is setup with an action of: Run Program PowerShell.exe Arguments: -executionpolicy bypass -file D:\Scripts\SomeScript.ps1

The script completes successfully and in task manager I can see PowerShell start then close, but Task Scheduler still shows it Running.

Any suggestions on how to fix this?

2 Answers 2

11

Just a tiny note: If you run a task manually it will go to "running" in task scheduler library. Wait until your task finishes and then hit F5 to refresh.

2
  • 3
    OMG that works - but isn't it ridiculous that you have to do this?!
    – Simon E
    Nov 3, 2021 at 19:11
  • 1
    You save my day. I've spent whole day trying to figure out what's wrong with my schedule or powershell. Ended up I just need a F5 Apr 2, 2022 at 2:55
4

Even though the script was doing everything it was configured to it seems I needed to place all of the arguments inside quotes.

Old arguments (everything completed fine but task hung): -executionpolicy bypass -file 'D:\Scripts\SomeScript.ps1'

New arguments (everything still completes fine including the Task): "-executionpolicy bypass -file 'D:\Scripts\SomeScripts.ps1'"

Not sure why this one server is requiring quotes, I run this exact script on multiple servers running the save version of Windows and same version of PowerShell, NONE of them have the quotes, but it works.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .