BUG: ScheduledTasks module broken in 1511
ICAN use New-SchedualedTaskTrigger -AtSartup without error SO THAT I can schedule tasks
Repeat issue: update win10 to 1511 and run this command in PowerShell
New-ScheduledTaskTrigger -AtStartup
New-ScheduledTaskTrigger : Method "NewTriggerByStartup" not found
At line:1 char:1
+ New-ScheduledTaskTrigger -AtStartup
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [New-ScheduledTaskTrigger], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041002,New-ScheduledTaskTrigger

7 comments
-
Michel Boivin commented
Ran into the exact same issue on a few systems. Running "mofcomp C:\Windows\System32\wbem\SchedProv.mof" does resolve the problem.
I'm calling the New-ScheduledTaskTrigger cmdlet as part of the installation
process of an application I'm developing. I'm concerned about adverse effects
of calling mofcomp without the user being aware. Should mofcomp be reserved to
sys admins or it's a failure safe operation I can add to my installation
process without risk? -
guitarrapc_tech commented
Any update with? I have this issue long time with WMF 5 and also other users experience same issues. https://github.com/guitarrapc/DSCResources/issues/58
-
Robert Smit commented
Got this issue during the deployment from Azurestack. This need to be fixed in TP5
-
Mathieu Buisson commented
Well done David !
After running the command : mofcomp C:\Windows\System32\wbem\SchedProv.mof ,
I have no problem anymore with the parameter -Once as well.Also, it made additional methods visible for the PS_ScheduledTask CIM class :
PS C:\> $PS_ScheduledTaskClass = Get-CimClass -Namespace root/Microsoft/Windows/TaskScheduler -ClassName PS_Sched
uledTask
PS C:\> $PS_ScheduledTaskClass.CimClassMethods.Name
RegisterByObject
RegisterByPrincipal
RegisterByUser
RegisterByXml
NewActionByExec
NewPrincipalByGroup
NewPrincipalByUser
NewSettings
StartByObject
StartByPath
StopByObject
StopByPath
SetByObject
SetByPrincipal
SetByUser
GetInfoByName
GetInfoByObject
New
ExportByName
ExportByObject
EnableByName
EnableByObject
DisableByName
DisableByObject
NewTriggerByDaily
NewTriggerByOnce
NewTriggerByLogon
NewTriggerByStartup
NewTriggerByWeekly -
Mathieu Buisson commented
Same error when using the -Once parameter of New-ScheduledTaskTrigger .
For example :
PS C:\> New-ScheduledTaskTrigger -Once -At "18:00"
New-ScheduledTaskTrigger : Method "NewTriggerByOnce" not found
At line:1 char:1
+ New-ScheduledTaskTrigger -Once -At "18:00"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [New-Schedul
edTaskTrigger], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041002,New-ScheduledTaskTriggerI am also using build 1511 of Windows 10.
PS C:\> $PSVersionTableName Value
---- -----
PSVersion 5.0.10586.63
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.63
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1This has been encountered by several people, here for example :
http://powershell.org/wp/forums/topic/method-newtriggerbyonce-not-found/This may be interesting information to troubleshoot :
PS C:\> $error[0].categoryinfo
Category : ObjectNotFound
Activity : New-ScheduledTaskTrigger
Reason : CimException
TargetName : PS_ScheduledTask
TargetType : Root/Microsoft/Windows/TaskScheduler/PS_ScheduledTaskIt seems the cmdlet cannot find a method called "NewTriggerByOnce" of the CIM class PS_ScheduledTask.
PS C:\> $PS_ScheduledTaskClass = Get-CimClass -Namespace root/Microsoft/Windows/TaskScheduler -ClassName PS_ScheduledTask
PS C:\> $PS_ScheduledTaskClass.CimClassMethods.Name
RegisterByObject
RegisterByPrincipal
RegisterByUser
RegisterByXml
NewActionByExec
NewPrincipalByGroup
NewPrincipalByUser
NewSettings
StartByObject
StartByPath
StopByObject
StopByPath
SetByObject
SetByPrincipal
SetByUser
GetInfoByName
GetInfoByObject
New
ExportByName
ExportByObject
EnableByName
EnableByObject
DisableByName
DisableByObjectIndeed, the method is not visible here.
PS C:\> Get-CimClass -MethodName "*TriggerByOnce*"
--> Nothing.
So I can't see any CIM class which has a method with a name similar to what the cmdlet is looking for. -
David Jones commented
In summary. from an elevated prompt run
mofcomp C:\Windows\System32\wbem\SchedProv.mof
-
David Jones commented
workarround:
PS C:\WINDOWS\system32> New-ScheduledTaskTrigger -AtStartup
New-ScheduledTaskTrigger : Method "NewTriggerByStartup" not found
At line:1 char:1
+ New-ScheduledTaskTrigger -AtStartup
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [New-ScheduledTaskT
rigger], CimException
+ FullyQualifiedErrorId : HRESULT 0x80041002,New-ScheduledTaskTriggerPS C:\WINDOWS\system32> mofcomp C:\Windows\System32\wbem\SchedProv.mof
Microsoft (R) MOF Compiler Version 10.0.10586.0
Copyright (c) Microsoft Corp. 1997-2006. All rights reserved.
Parsing MOF file: C:\Windows\System32\wbem\SchedProv.mof
MOF file has been successfully parsed
Storing data in the repository...
Done!
PS C:\WINDOWS\system32> New-ScheduledTaskTrigger -AtStartupEnabled : True
EndBoundary :
ExecutionTimeLimit :
Id :
Repetition :
StartBoundary :
Delay :
PSComputerName :PS C:\WINDOWS\system32>