2

I have a Powershell script (on Windows Server 2008 R2) which runs successfully from console.

When I run it from Task Scheduler it does not enter the script and task completes with a status of 0x1.

The account running the script is an administrator.

enter image description here

enter image description here

Community
  • 1
  • 1
Akshay
  • 113
  • 1
  • 14
  • Can you also show the Action? – Kage Oct 01 '16 at 08:37
  • Yes. I know why you want to see it it because the problem is there itself. The name of the folder where script is kept has spaces. Therefore, when I chose program/script , the task scheduler would take up apostrophes (" "). After a long struggle I got to know the solution. It is pasted in the answer section. – Akshay Oct 01 '16 at 09:30

1 Answers1

4

The folder where the script was present was

D:\Some Folder\script.ps1

The folder name had spaces. So when I added the action in the task scheduler to run a program/script , the scheduler itself would put apostrophes (" ") and the action would look something like below:-

enter image description here

After long struggle I found out that the apostrophes were causing the task scheduler not to run the script.

To fix this , there are two solutions :-

  1. Change the folder name to something without spaces
  2. Pass the script as argument. This can be done by changing the below:-

program /script : Powershell.exe
the argument : -file "D:\Your folder name with space\your_script.ps1"

Below is the grab from my task scheduler.

enter image description here

Hope this helps everyone who faces such problem .

Community
  • 1
  • 1
Akshay
  • 113
  • 1
  • 14