Method "NewTriggerByOnce" not found

Here is what I’m trying to do (Add trigger to scheduled task on remote machine):

Invoke-Command -ComputerName BETA -ScriptBlock {Set-ScheduledTask -TaskPath '\Monitor\' -TaskNam
e 'Off' -Trigger (New-ScheduledTaskTrigger -At 16:40 -Once)}

which results into:

Method "NewTriggerByOnce" not found
    + CategoryInfo          : ObjectNotFound: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [New-ScheduledTaskT
   rigger], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041002,New-ScheduledTaskTrigger
    + PSComputerName        : BETA

Cannot validate argument on parameter 'Trigger'. The argument is null or empty. Provide an argument that is not null or
 empty, and then try the command again.
    + CategoryInfo          : InvalidData: (:) [Set-ScheduledTask], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Set-ScheduledTask
    + PSComputerName        : BETA

wondering may be someone have same issue?

What version of Windows and PowerShell are you using on the local and remote machines?

I’ve reproduced your error on a windows 10 machine
PS> New-ScheduledTaskTrigger -At 16:40 -Once
New-ScheduledTaskTrigger : Method “NewTriggerByOnce” not found
At line:1 char:1

  • New-ScheduledTaskTrigger -At 16:40 -Once
  •   + CategoryInfo          : ObjectNotFound: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [New-ScheduledTaskT
     rigger], CimException
      + FullyQualifiedErrorId : HRESULT 0x80041002,New-ScheduledTaskTrigger
    
    

Using the production preview of WMF 5.0 on Windows Server 2012 R2 command works and I can create the trigger.

I’ve also found a difference between the commands on the 2 versions of PowerShell.

I’ll investigate this further. Something isn’t right somewhere

Oh, it seems that you are right, I just have tried that script from home laptop to work pc all works (both have Windows 10) but machine that I was tried before have Windows 10 Insider Preview, so probably there is some kind of regression, hope that it will not happen later on in normal Windows 10

Running regular Windows 10 with the following PS Version and still getting the same type of error when trying to create a daily trigger. Any updates?

Name Value


PSVersion 5.0.10586.0
PSCompatibleVersions {1.0, 2.0, 3.
BuildVersion 10.0.10586.0
CLRVersion 4.0.30319.420
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Report it here then: http://windowsserver.uservoice.com/forums/301869-powershell :slight_smile:

found a fix and posted it user voice.
From an elevated prompt (PowerShell or CMD)
mofcomp C:\Windows\System32\wbem\SchedProv.mof

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-ScheduledTaskTrigger

PS 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 -AtStartup


Enabled            : True
EndBoundary        :
ExecutionTimeLimit :
Id                 :
Repetition         :
StartBoundary      :
Delay              :
PSComputerName     :



PS C:\WINDOWS\system32>

Thank you David.

Recompiling SchedProv.mof fixed my error when trying to create a scheduled task with a daily trigger: New-ScheduledTaskTrigger : Method “NewTriggerByDaily” not found

I have a Win 8.1 to Win 10 upgraded machine with
PSVersion 5.0.10586.122
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
BuildVersion 10.0.10586.122
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1