I use a script to create a windows scheduled task to call a powershell script in elevated mode to run windows update by using boxstarter (a tool could automatically continue running code even there is reboot during the execution) when system startup. But not sure why, the task could be called after startup, but nothing has been done. If I manually start the scheduled task in task manager, it will run as expected.
Script to register a scheduled task:
$TaskActionArgument ="-noprofile -command "&{start-process powershell -argumentList '-File C:\users\administrator\updatescript\boxstarter.ps1 -verb runas'}""
$TaskAction = New-ScheduledTaskAction -Execute "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -argument $TaskActionArgument
$TaskTrigger = New-ScheduledTaskTrigger -AtStartup
Register-ScheduledTask -TaskName boxstarter -Action $TaskAction -Trigger $TaskTrigger -User administrator -Password Vmc12svt -RunLevel Highest
I checked the event log viewer and see following error message for the scheduled job:
System
Provider
[ Name] PowerShell
EventID 403
[ Qualifiers] 0
Level 4
Task 4
Keywords 0x80000000000000
TimeCreated
[ SystemTime] 2018-01-10T18:21:12.000000000Z
EventRecordID 267
Channel Windows PowerShell
Computer WIN-6HSHKOKP31E
Security
- EventData
Stopped Available NewEngineState=Stopped PreviousEngineState=Available SequenceNumber=16 HostName=ConsoleHost HostVersion=4.0 HostId=13ece112-b027-4051-9ddf-1a195d3aa30f HostApplication=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\users\administrator\updatescript\boxstarter.ps1 -verb runas EngineVersion=4.0 RunspaceId=d158a216-18e3-4e86-9ade-b232201c9cdc PipelineId= CommandName= CommandType= ScriptName= CommandPath= CommandLine=
For the error message, I googled and found explain of error code here
In general, the page says such issue could be caused by following error:
- The Task Scheduler service is disabled
- The COM service is disabled
- The Windows Event Log service is disabled
- The RPC service is disabled
- There is not enough free memory
Non of above is true for my system.
So what's error with my scheduled task? How could I make it work?