PowerShell Logo Small

New-JobTrigger



This is the built-in help made by Microsoft for the command 'New-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

Creates a job trigger for a scheduled job

SYNTAX


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



Search powershellhelp.space

DESCRIPTION


The New-JobTrigger cmdlet creates a "job trigger" that starts a scheduled job on a one-time or recurring schedule, or when an event occurs.


You can use the ScheduledJobTrigger object that New-JobTrigger returns to set a job trigger for a new or existing scheduled job. You can also create a job trigger by using
the Get-JobTrigger cmdlet to get the job trigger of an existing scheduled job, or by using a hash table value to represent a job trigger.


When creating a job trigger, review the default values of the options specified by the New-ScheduledJobOption cmdlet. These options, which have the same valid and default
values as the corresponding options in Task Scheduler, affect the scheduling and timing of scheduled jobs.


New-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=290628
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: Once Schedule

PS C:\>New-JobTrigger –Once –At "1/20/2012 3:00 AM"



This command uses the New-JobTrigger cmdlet to create a job trigger that starts a scheduled job only one time. The value of the At parameter is a string that Windows
PowerShell converts into a DateTime object. The At parameter value includes an explicit date, not just a time. If the date were omitted, the trigger would be created with
the current date and 3:00 AM time, which is likely to represent a time in the past.




Example 2: Daily Schedule

PS C:\>New-JobTrigger –Daily –At "4:15 AM" –DaysInterval 3
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
0 Daily 9/21/2012 4:15:00 AM True



This command creates a job trigger that starts a scheduled job every 3 days at 4:15 a.m.

Because the value of the At parameter does not include a date, the current date is used as the date value in the DateTime object. If the date and time is in the past, the
scheduled job is started at the next occurrence, which is 3 days later from the At parameter value.




Example 3: Weekly Schedule

PS C:\>New-JobTrigger –Weekly –DaysOfWeek Monday, Wednesday, Friday –At "23:00" –WeeksInterval 4
Id Frequency Time DaysOfWeek Enabled
-- --------- ---- ---------- -------
0 Weekly 9/21/2012 11:00:00 PM {Monday, Wednesday, Friday} True



This command creates a job trigger that starts a scheduled job every 4 weeks on Monday, Wednesday, and Friday at 2300 hours (11:00 PM).

You can also enter the DaysOfWeek parameter value in integers, such as "-DaysOfWeek 1, 5".




Example 4: Logon Schedule

PS C:\>New-JobTrigger -AtLogOn -User Domain01\Admin01



This command creates a job trigger that starts a scheduled job whenever the domain administrator logs onto the computer.




Example 5: Using a Random Delay

PS C:\>New-JobTrigger –Daily –At 1:00 –RandomDelay 00:20:00



This command creates a job trigger that starts a scheduled job every day at 1:00 in the morning. The command uses the RandomDelay parameter to set the maximum delay to 20
minutes. As a result, the job runs every day between 1:00 AM and 1:20 AM, with the interval varying pseudo-randomly.

You can use a random delay for sampling, load balancing, and other administrative tasks. When setting the delay value, review the effective and default values of the
New-ScheduledJobOption cmdlet and coordinate the delay with the option settings.




Example 6: Create a Job Trigger for a New Scheduled Job

The first command uses the New-JobTrigger cmdlet to create a job trigger that starts a job every Monday, Wednesday, and Friday at 12:01 a.m. The command saves the job
trigger in the $t variable.
PS C:\>$t = New-JobTrigger –Weekly –DaysOfWeek 1,3,5 –At 12:01AM


The second command uses the Register-ScheduledJob cmdlet to create a scheduled job that starts a job every Monday, Wednesday, and Friday at 12:01 a.m. The value of the
Trigger parameter is the trigger that is stored in the $t variable.
PS C:\>Register-ScheduledJob -Name Test-HelpFiles -FilePath C:\Scripts\Test-HelpFiles.ps1 -Trigger $t



These commands use a job trigger to create a new scheduled job.




Example 7: Add a Job Trigger to a Scheduled Job

PS C:\>Add-JobTrigger -Name SynchronizeApps -Trigger (New-JobTrigger -Daily -At 3:10AM)



This example shows how to add a job trigger to an existing scheduled job. You can add multiple job triggers to any scheduled job.

The command uses the Add-JobTrigger cmdlet to add the job trigger to the SynchronizeApps scheduled job. The value of the Trigger parameter is a New-JobTrigger command that
runs the job every day at 3:10 AM.

When the command completes, SynchronizeApps is a scheduled job that runs at the times specified by the job trigger.




Example 8: Create a repeating job trigger

PS C:\>New-JobTrigger -Once -At "09/12/2013 1:00:00" -RepetitionInterval (New-TimeSpan -Hours 1) -RepetitionDuration (New-Timespan -Hours 48)



This command creates a job trigger that runs a job every 60 minutes for 48 hours beginning on September 12, 2013 at 1:00 a.m.




Example 9: Stop a repeating job trigger

PS C:\>Get-JobTrigger -Name SecurityCheck | Set-JobTrigger –RepetitionInterval 0:00 –RepetitionDuration 0:00



This command forcibly stops the SecurityCheck job, which is triggered to run every 60 minutes until its job trigger expires.

To prevent the job from repeating, the command uses the Get-JobTrigger to get the job trigger of the SecurityCheck job and the Set-JobTrigger cmdlet to change the repetition
interval and repetition duration of the job trigger to zero (0).




Example 10: Create an hourly job trigger

PS C:\>New-JobTrigger -Once -At "9/21/2012 0am" -RepetitionInterval (New-TimeSpan -Hour 12) -RepetitionDuration ([TimeSpan]::MaxValue)



The following command creates a job trigger that runs a scheduled job once every 12 hours for an indefinite period of time. The schedule begins tomorrow (9/21/2012) at
midnight (0:00 AM).