CmdID

CmdID / PowerShell / Cmdlets / New

New-JobTrigger

Creates a job trigger for a scheduled job. PowerShell reference

From the PowerShell reference 14 parameters

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Creates a job trigger for a scheduled job. 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 with the Get-JobTrigger cmdlet to get the job trigger of an existing scheduled job, or with 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 was introduced in Windows PowerShell 3.0.

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

Once Schedule

New-JobTrigger -Once -At "1/20/2012 3:00 AM"Identify

Daily Schedule

New-JobTrigger -Daily -At "4:15 AM" -DaysInterval 3Identify

Weekly Schedule

New-JobTrigger -Weekly -DaysOfWeek Monday, Wednesday, Friday -At "23:00" -WeeksInterval 4Identify

Logon Schedule

New-JobTrigger -AtLogOn -User Domain01\Admin01Identify

Using a Random Delay

New-JobTrigger -Daily -At 1:00 -RandomDelay 00:20:00Identify

Create a Job Trigger for a New Scheduled Job

$t = New-JobTrigger -Weekly -DaysOfWeek 1,3,5 -At 12:01AM Register-ScheduledJob -Name Test-HelpFiles -FilePath C:\Scripts\Test-HelpFiles.ps1 -Trigger $tIdentify

Add a Job Trigger to a Scheduled Job

Add-JobTrigger -Name SynchronizeApps -Trigger (New-JobTrigger -Daily -At 3:10AM)Identify

Create a repeating job trigger

$newJobTriggerSplat = @{ Once = -Once At = "09/12/2013 1:00:00" RepetitionInterval = (New-TimeSpan -Hours 1) RepetitionDuration = (New-TimeSpan -Hours 48) } New-JobTrigger @newJobTriggerSplatIdentify

Stop a repeating job trigger

Get-JobTrigger -Name SecurityCheck | Set-JobTrigger -RepetitionInterval 0:00 -RepetitionDuration 0:00Identify

Create an hourly job trigger

$newJobTriggerSplat = @{ Once = -Once At = "9/21/2012 0am" RepetitionInterval = (New-TimeSpan -Hour 12) RepetitionDuration = ([timespan]::MaxValue) } New-JobTrigger @newJobTriggerSplatIdentify

Its page in the reference: New-JobTrigger.

Parameters

14 in the PowerShell reference
-AtStarts the job at the specified date and time. Enter a DateTime object, such as one that the Get-Date cmdlet returns, or a string that can be converted to a date and time, such as April 19, 2012 15:00, 12/31, or 3am. If you don't specify an element of the date, such as the year, the date in the trigger has the corresponding element from the current date. When using the Once parameter, set the value of the At parameter to a future date and time. Because the default date in a DateTime object is the current date, if you specify a time before the current time without an explicit date, the job trigger is created for a time in the past. DateTime objects, and strings that are converted to DateTime objects, are automatically adjusted to be compatible with the date and time formats selected for the local computer in Region and Language in Control Panel.
-AtLogOnStarts the scheduled job when the specified users log on to the computer. To specify a user, use the User parameter.
-AtStartupStarts the scheduled job when Windows starts.
-DailySpecifies a recurring daily job schedule. Use the other parameters in the Daily parameter set to specify the schedule details.
-DaysIntervalSpecifies the number of days between occurrences on a daily schedule. For example, a value of 3 starts the scheduled job on days 1, 4, 7 and so on. The default value is 1.
-DaysOfWeekSpecifies the days of the week on which a weekly scheduled job runs. Enter day names, such as Monday or integers 0-6, where 0 represents Sunday. This parameter is required in the Weekly parameter set. Day names are converted to their integer values in the job trigger. When you enclose day names in quotation marks in a command, enclose each day name in separate quotation marks, such as "Monday", "Tuesday". If you enclose multiple day names in a single quotation mark pair, the corresponding integer values are summed. For example, "Monday, Tuesday" (1 + 2) results in a value of Wednesday (3).
-OnceSpecifies a non-recurring (one time) or custom repeating schedule. To create a repeating schedule, use the Once parameter with the RepetitionDuration and RepetitionInterval parameters.
-RandomDelayEnables a random delay that begins at the scheduled start time, and sets the maximum delay value. The length of the delay is set pseudo-randomly for each start and varies from no delay to the time specified by the value of this parameter. The default value, zero (00:00:00), disables the random delay. Enter a timespan object, such as one returned by the New-TimeSpan cmdlet, or enter a value in <hours>:<minutes>:<seconds> format, which is automatically converted to a TimeSpan object.
-RepeatIndefinitelyThis parameter, available starting in Windows PowerShell 4.0, eliminates the necessity of specifying a TimeSpan.MaxValue value for the RepetitionDuration parameter to run a scheduled job repeatedly, for an indefinite period.
-RepetitionDurationRepeats the job until the specified time expires. The repetition frequency is determined by the value of the RepetitionInterval parameter. For example, if the value of RepetitionInterval is 5 minutes and the value of RepetitionDuration is 2 hours, the job is triggered every five minutes for two hours. Enter a timespan object, such as one that the New-TimeSpan cmdlet returns or a string that can be converted to a timespan object, such as 1:05:30. To run a job indefinitely, add the RepeatIndefinitely parameter instead. To stop a job before the job trigger repetition duration expires, use the Set-JobTrigger cmdlet to set the RepetitionDuration value to zero (0). This parameter is valid only when the Once, At, and RepetitionInterval parameters are used in the command.
-RepetitionIntervalRepeats the job at the specified time interval. For example, if the value of this parameter is 2 hours, the job is triggered every two hours. The default value, 0, does not repeat the job. Enter a timespan object, such as one that the New-TimeSpan cmdlet returns or a string that can be converted to a timespan object, such as 1:05:30. This parameter is valid only when the Once, At, and RepetitionDuration parameters are used in the command.
-UserSpecifies the users who trigger an AtLogon start of a scheduled job. Enter the name of a user in <UserName> or <Domain\Username> format or enter an asterisk (*) to represent all users. The default value is all users.
-WeeklySpecifies a recurring weekly job schedule. Use the other parameters in the Weekly parameter set to specify the schedule details.
-WeeksIntervalSpecifies the number of weeks between occurrences on a weekly job schedule. For example, a value of 3 starts the scheduled job on weeks 1, 4, 7 and so on. The default value is 1.