PowerShell Logo Small

Set-JobTrigger



This is the built-in help made by Microsoft for the command 'Set-JobTrigger', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Changes the job trigger of a scheduled job.

SYNTAX


Set-JobTrigger [-InputObject] <ScheduledJobTrigger[]> [-At <DateTime>] [-AtLogOn] [-AtStartup] [-Daily] [-DaysInterval <Int32>] [-DaysOfWeek <DayOfWeek[]>] [-Once]
[-PassThru] [-RandomDelay <TimeSpan>] [-RepeatIndefinitely] [-RepetitionDuration <TimeSpan>] [-RepetitionInterval <TimeSpan>] [-User <String>] [-Weekly] [-WeeksInterval
<Int32>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Set-JobTrigger cmdlet changes the properties of the job triggers of scheduled jobs. You can use it to change the time or frequency at which the jobs start or to change
from a time-based schedules to schedules that are triggered by a logon or startup.


A "job trigger" defines a recurring schedule or conditions for starting a scheduled job. Although job triggers are not saved to disk, you can change the job triggers of
scheduled jobs, which are saved to disk.


To change a job trigger of a scheduled job, begin by using the Get-JobTrigger cmdlet to get the job trigger of a scheduled job. Then, pipe the trigger to Set-JobTrigger or
save the trigger in a variable and use the InputObject parameter of Set-JobTrigger cmdlet to identify the trigger. Use the remaining parameters of Set-JobTrigger to change
the job trigger.


When you change the type of a job trigger, such as changing a job trigger from a daily or weekly trigger to an AtLogon trigger, the original trigger properties are deleted.
However, if you change the values of the trigger, but not its type, such as changing the days in a weekly trigger, only the properties that you specify are changed. All
other properties of the original job trigger are retained.


Set-JobTrigger is one of a collection of job scheduling cmdlets in the PSScheduledJob module that is included in Windows PowerShell.


For more information about Scheduled Jobs, see the About topics in the PSScheduledJob module. Import the PSScheduledJob module and then type: Get-Help about_Scheduled* or
see about_Scheduled_Jobs.


This cmdlet is introduced in Windows PowerShell 3.0.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=290632
about_Scheduled_Jobs
Add-JobTrigger
Disable-JobTrigger
Disable-ScheduledJob
Enable-JobTrigger
Enable-ScheduledJob
Get-JobTrigger
Get-ScheduledJob
Get-ScheduledJobOption
New-JobTrigger
New-ScheduledJobOption
Register-ScheduledJob
Remove-JobTrigger
Set-JobTrigger
Set-ScheduledJob
Set-ScheduledJobOption
Unregister-ScheduledJob

REMARKS

<

Examples


Example 1: Change the days in a job trigger

The first command uses the Get-JobTrigger cmdlet to get the job trigger of the DeployPackage scheduled job. The output shows that the trigger starts the job at midnight on
Wednesdays and Saturdays.This command is not required; it is included only to show the effect of the trigger change.
PS C:\>Get-JobTrigger -Name DeployPackage
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
1 Weekly 9/29/2011 12:00:00 AM {Wednesday, Saturday} True

The second command uses the Get-JobTrigger cmdlet to get the job trigger of the DeployPackage scheduled job. A pipeline operator (|) sends the trigger to the Set-JobTrigger
cmdlet which changes the job trigger so that it starts the DeployPackage job on Wednesdays and Sundays. The command uses the Passthru parameter to return the trigger after
the change.
PS C:\>Get-JobTrigger -Name DeployPackage | Set-JobTrigger -DaysOfWeek "Wednesday", "Sunday" -Passthru
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
1 Weekly 9/29/2011 12:00:00 AM {Wednesday, Sunday} True



This example shows how to change the days in a weekly job trigger.




Example 2: Change the job trigger type

The first command uses the Get-JobTrigger cmdlet to get the job trigger of the Inventory scheduled job. The output shows that the job has two triggers a daily trigger and an
AtStartup trigger.This command is not required; it is included only to show the effect of the trigger change.
PS C:\>Get-JobTrigger -Name Inventory
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
1 Daily 9/27/2011 11:00:00 PM True
2 AtStartup True

The second command uses the Get-JobTrigger cmdlet to get the AtStartup job trigger of the Inventory job. The command uses the TriggerID parameter to identify the job
trigger. A pipeline operator (|) sends the job trigger to the Set-JobTrigger cmdlet which changes it to a weekly job trigger that runs every four weeks on Monday at
midnight. The command uses the Passthru parameter to return the trigger after the change.
PS C:\>Get-JobTrigger -Name Inventory -TriggerID 2 | Set-JobTrigger -Weekly -WeeksInterval 4 -DaysOfWeek Monday -At "12:00 AM"
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
1 Daily 9/27/2011 11:00:00 PM True
2 Weekly 10/31/2011 12:00:00 AM {Monday} True



This example shows how to change the type of job trigger that starts a job. The commands in this example replace an AtStartup job trigger with a weekly trigger.




Example 3: Change the user on a remote job trigger

PS C:\>Invoke-Command -Computer Server01 -ScriptBlock {Get-ScheduledJob | Get-JobTrigger | Where-Object {$_.User} | Set-JobTrigger -User "Domain01/Admin02"}



This command changes the user in all AtLogon job triggers of scheduled jobs on the Server01 computer.

The command uses the Invoke-Command cmdlet to run a command on the Server01 computer.

The remote command begins with a Get-ScheduledJob command that gets all scheduled jobs on the computer. The scheduled jobs are piped to the Get-JobTrigger cmdlet, which
gets the job triggers of the scheduled jobs. Each job trigger contains a JobDefinition property that contains the scheduled job, so the trigger remains associated with the
scheduled job even when it is changed.

The job triggers are piped to the Where-Object cmdlet which gets job triggers that have the User property. The selected job triggers are piped to the Set-JobTrigger cmdlet,
which changes the user to Domain01\Admin02.




Example 4: Change one of many job triggers

The first command uses the Get-JobTrigger cmdlet to get all job triggers of the SecurityCheck scheduled job. The output, which displays the IDs of the job triggers, reveals
that the Once job trigger has an ID of 3.
PS C:\>Get-JobTrigger -Name SecurityCheck
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
1 Daily 4/24/2013 3:00:00 AM True
2 Weekly 4/24/2013 4:00:00 PM {Sunday} True
3 Once 4/24/2013 4:00:00 PM True

The second command uses the TriggerID parameter of the Get-JobTrigger cmdlet to get the Once trigger of the SecurityCheck scheduled job. The command pipes the trigger to the
Format-List cmdlet, which displays all of the properties of the Once job trigger.The output shows that the trigger starts the job once every hour (RepetitionInterval = 1
hour) for one day (RepetitionDuration = 1 day).
PS C:\>Get-JobTrigger -Name SecurityCheck -TriggerID 3 | Format-List -Property *
At : 4/24/2012 4:00:00 PM
DaysOfWeek :
Interval : 1
Frequency : Once
RandomDelay : 00:00:00
RepetitionInterval : 01:00:00
RepetitionDuration : 1.00:00:00
User :
Id : 3
Enabled : True
JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition

The third command changes the repetition interval of the job trigger from one hour to 90 minutes. The command does not return any output.
PS C:\>Get-JobTrigger -Name SecurityCheck -TriggerId 3 | Set-JobTrigger -RepetitionInterval (New-TimeSpan -Minutes 90)

The fourth command displays the effect of the change.The output shows that the trigger starts the job once every 90 minutes (RepetitionInterval = 1 hour, 30 minutes) for one
day (RepetitionDuration = 1 day).
PS C:\>Get-JobTrigger -Name SecurityCheck -TriggerID 3 | Format-List -Property *
At : 4/24/2012 4:00:00 PM
DaysOfWeek :
Interval : 1
Frequency : Once
RandomDelay : 00:00:00
RepetitionInterval : 01:30:00
RepetitionDuration : 1.00:00:00
User :
Id : 3
Enabled : True
JobDefinition : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition



The commands in this example changes the repetition interval of the Once job trigger of SecurityCheck scheduled job from every 60 minutes to every 90 minutes. The
SecurityCheck scheduled job has three job triggers, so the commands use the TriggerId parameter of the Get-JobTrigger cmdlet to identify the job trigger that is being
changed.