Method "NewTriggerByOnce" not found, TaskScheduler

Welcome Forums General PowerShell Q&A Method "NewTriggerByOnce" not found, TaskScheduler

This topic contains 4 replies, has 4 voices, and was last updated by

 
Participant
2 years, 5 months ago.

  • Author
    Posts
  • #33817

    Participant
    Points: 0
    Rank: Member

    Hello! Iam pretty new in Powershell and sorry for my lousy English.

    Iam trying to add a task in Task Scheduler throu Powershell, here is the Code so far.

    $Action = New-ScheduledTaskAction -Execute "C:\BackupScript\CopyFiles.ps1"
    $Trigger = New-ScheduledTaskTrigger -Daily -At '11AM'
    $Principal = New-ScheduledTaskPrincipal -UserId $env:username -RunLevel Highest
    $Settings  = New-ScheduledTaskSettingsSet -RunOnlyIfNetworkAvailable -WakeToRun
    $Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Principal $Principal -Settings $Settings
    $Task | Register-ScheduledTask -TaskName 'AndreasBackup'
    

    When running the cmdlet New-ScheduledTaskTrigger (Line 2), I get the following error:

    "New-ScheduledTaskTrigger : Method "NewTriggerByDaily" not found
    At line:2 char:12
    + $Trigger = New-ScheduledTaskTrigger -Daily -At '11AM'
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [New-ScheduledTaskTrigger], CimExc
    eption
    + FullyQualifiedErrorId : HRESULT 0x80041002,New-ScheduledTaskTrigger"

    No matter how I try, I can't get that cmdlet to work.. Not even with the examples from https://technet.microsoft.com/en-us/library/jj649821(v=wps.630).aspx

    Iam running PS version 5, build 10586 on my Windows 10 machine.

    Any ideas?

  • #33828

    Keymaster
    Points: 8
    Rank: Member

    It sounds like something is screwed up on your machine, because I'm not able to reproduce the error. Unfortunately, I'm not sure what to look for, here. Do you have another machine you can test on?

  • #33997

    Participant
    Points: 0
    Rank: Member

    I have the same issue. it seems to be only machines that were upgraded from 8.1 to win10 then upgraded to 1511. (every machine I have)
    a fresh install of 1511 does not have the issue.

  • #34036

    Participant
    Points: 0
    Rank: Member

    Hello, and sorry for the late answer.. I have been testing on some other Windows 10 machines aswell, but still unable to run the script.

    Instead I used the new set of cmdlets released in Powershell version 5. Now It looks something like this:

    $Trigger = New-JobTrigger -Daily -At 1:21PM
    $Options = New-ScheduledJobOption -WakeToRun -RequireNetwork
     Register-ScheduledJob -Name "AndreasJob" {C:\BackupScript\CopyFiles.ps1} -Trigger $trigger -ScheduledJobOption $options
    

    Here is the link to what's new in Powershell Version 5.
    https://technet.microsoft.com/en-us/library/hh857339.aspx

  • #39917

    Participant
    Points: 0
    Rank: Member

    I had a similar problem with New-ScheduledTaskTrigger -Daily giving the error "NewTriggerByDaily" not found. Some more Googling found a thread on windowsserver.uservoice.com with the answer:

    PS C:\> mofcomp C:\Windows\System32\wbem\SchedProv.mof

    New-ScheduledTaskTrigger now works correctly.

The topic ‘Method "NewTriggerByOnce" not found, TaskScheduler’ is closed to new replies.