Change 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] Key -At DateTime Starts 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. -AtLogOn Start the scheduled job when the specified users log on to the computer. To specify a user, use -User -AtStartup Start the scheduled job when Windows starts. -Daily Specify a recurring daily job schedule. Use the other parameters in the Daily parameter set to specify the schedule details. -DaysInterval Int32 Specify 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. -DaysOfWeek DayOfWeek[] Specify 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. NOTE: 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). -InputObject ScheduledJobTrigger[] Specifies the job triggers. Enter a variable that contains ScheduledJobTrigger objects or type a command or expression that gets ScheduledJobTrigger objects, such as a Get-JobTrigger command. You can also pipe a ScheduledJobTrigger object to Set-JobTrigger. If you specify multiple job triggers, Set-JobTrigger makes the same changes to all job triggers. -Once Specify a non-recurring (one time) or custom repeating schedule. To create a repeating schedule, use the Once parameter with the RepetitionDuration and RepetitionInterval parameters. -PassThru Returns the job triggers that changed. By default, this cmdlet does not generate any output. -RandomDelay TimeSpan Enable a random delay that begins at the scheduled start time, and set 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. -RepeatIndefinitely This 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. -RepetitionDuration TimeSpan Repeats 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. -RepetitionInterval TimeSpan Repeat 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 with the -Once, -At, and -RepetitionDuration parameters. (for a -Once job trigger, the command must include both -RepetitionInterval and -RepetitionDuration.) -User String Specify 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. -Weekly Specify a recurring weekly job schedule. Use the other parameters in the Weekly parameter set to specify the schedule details. -WeeksInterval Int32 Specify 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. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -PipelineVariable, -OutVariable.
Examples
Get the job trigger of the DemoJob scheduled job and pipe it to Set-JobTrigger, changing the days of the week to Wednesdays and Sundays:
C:\PS> Get-JobTrigger -Name DemoJob | Set-JobTrigger -DaysOfWeek "Wednesday", "Sunday" -Passthru
List the job triggers, including their IDs for the SS64job scheduled job:
C:\PS> Get-JobTrigger -Name SS64job Id Frequency Time DaysOfWeek Enabled -- --------- ---- ---------- ------- 1 Daily 9/27/2015 11:00:00 PM True 2 AtStartup True
Create a job trigger that can start a scheduled job every Monday and every Friday:
PS C:\> New-JobTrigger –Weekly –DaysOfWeek Monday, Friday –At "23:00" –WeeksInterval 1
Change the user on a remote job trigger:
PS C:\> Invoke-Command -Computer Server64 -ScriptBlock {Get-ScheduledJob | Get-JobTrigger | Where-Object {$_.User} | Set-JobTrigger -User "Domain01/Admin02"}
“I can't change the direction of the wind, but I can adjust my sails to always reach my destination” ~ Jimmy Dean
Related PowerShell Cmdlets:
Scheduler cmdlets - Get/Set scheduled jobs.
Add-JobTrigger - Add a job trigger to a scheduled job.
Get-JobTrigger - Get the job triggers of scheduled jobs.
New-JobTrigger - Create a new Job Trigger.