PowerShell Script not running with the task scheduler

powershellscheduled-taskswindows-server-2012-r2

So I created a PowerShell script that installs Windows Updates,

As you may know, when installing updates, it's possible that the PC has to reboot (while there are still updates left) in order for installing the scripts.

What I implemented was a task that get's imported at the start of the script and runs the script after each reboot (and installs the remaining script at the logon screen) untill there are no more scripts left.

After the last updates, the script will remove the task out of the task scheduler.

My implementations (downloading/installing/adding the task /removing the task) work perfectly.

It's only that my script won't run after a reboot and I have no idea why!

This is my task:
enter image description here

After the pc get's rebooted though, the script doesn't run anymore and the error in the task scheduler states 0x1

I have done some Googling and found that the argument might be wrong (third picture WITH the path being correct of course) but I have tried (in the arguments field):

  • (no quotes) -file path
  • -ExecutionPolicy Bypass -file path
  • -NoProfile -ExecutionPolicy Bypass -file path -force
  • mixing above combinations with quotes added or left out

What could be the problem of the task scheduler not launching my script?

Thanks

EDIT

Added screenshot of Log on as a batch job properties:

enter image description here

Best Answer

The problem had to do with my START IN -being empty!

My script was at C:\Scripts\Scripts.ps1 so i had to fill in C:\Scripts\.

This is what you need to do apt or else the PS will start in the folder it's in (Windows folder).

Since the script uses other files, i had to specify the START IN path, it was solved after this .

Related Topic