3

I'm trying to use PowerShell to add a trigger to an existing scheduled task. I'm using Windows 10 & PowerShell 5

When I run:

Get-Scheduled-Job -Name TASK_NAME

I receive the error:

>Get-ScheduledJob : A scheduled job definition with Name sanityInstaller could not be found.
At line:1 char:1
+ Get-ScheduledJob sanityInstaller
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-ScheduledJob], RuntimeException
    + FullyQualifiedErrorId : ScheduledJobDefinitionNotFoundByName,Microsoft.PowerShell.ScheduledJob.GetScheduledJobCommand

It seems that even when I run the same command with no parameter it's expected to return all jobs but it returns an empty result.

In the Task Scheduler there's no such folder as /Microsoft/Windows/PowerShell/ScheduledJobs and even after I created it and a new task inside it doesn't return it.

What am I missing here ?

Avshalom
  • 8,657
  • 1
  • 25
  • 43
Ohad Benita
  • 533
  • 2
  • 8
  • 26

1 Answers1

6

Get-ScheduledJob gets only scheduled jobs that are created by the current user using the Register-ScheduledJob cmdlet.

Source.

You are looking for the Get-ScheduledTask cmdlet.

Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • I have another machine running Win7 where the [Get-ScheduledTask](http://go.microsoft.com/fwlink/p/?linkid=287549) cmdlet doesn't work, is there a way around this ? – Ohad Benita Jun 06 '16 at 09:22
  • Thanks for this, this really oblivious to me... I was able to hack this by first running Register-ScheduleJob and only then edit what I needed inside the job. Also, for future reference, the tasks created by Register-ScheduleJob are always executed using powershell and their xmls and results are saved @ C:\Users\MyUser\AppData\Local\Microsoft\Windows\PowerShell\ScheduledJobs, in task scheduler you can find them under Microsoft/Windows/PowerShell/ScheduleJobs – Ohad Benita Jun 06 '16 at 17:57