Reputation: 30892
I have created a powershell job that I can see when I use the following command:
PS C:\WINDOWS\system32> Get-ScheduledJob -Name KillTicker | Get-JobTrigger
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
1 AtStartup True
As this is a startup job I really don't fancy restarting to test it out - how to do I manually start this job?
Upvotes: 3
Views: 7302
Reputation: 129
I think it is worth it to mention that Start-Job or StartJob() both run the defined job from the current security context. If the job runs as different user or accesses network resources, you might get unexpected results.
To get the same behavior use either (Get-ScheduledJob -Name xxx).RunAsTask()
or Start-ScheduledTask -TaskName xxx -TaskPath xxx
. The latter provides a -CimSession
option and could be better for remote operations.
Upvotes: 1
Reputation: 35
You can use the Start-Job
cmdlet and supply the name of the Scheduled Job as the
-DefinitionName
parameter.
Start-Job -DefinitionName *MyJobName*
Upvotes: 0
Reputation: 58951
If you run Get-ScheduledJob -id 1 | Get-Member
to retrieve all Members of a Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition
you will see that the object expose a method called StartJob
:
(Get-ScheduledJob -id 1).StartJob()
To retrieve the result, use the Receive-Job cmdlet:
Receive-Job -id 1
Upvotes: 9