2

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?

Aaron O
  • 61
  • 1
  • 1
  • 5

2 Answers2

9

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.

Sniipe
  • 191
  • 1
  • 2
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.

Aaron O
  • 61
  • 1
  • 1
  • 5