CmdID / PowerShell / Cmdlets / New
New-ScheduledJobOption
Creates an object that contains advanced options for a scheduled job. PowerShell reference
From the PowerShell reference 13 parameters
What it does
Creates an object that contains advanced options for a scheduled job. The New-ScheduledJobOption cmdlet creates an object that contains advanced options for a scheduled job. You can use the ScheduledJobOptions object that New-ScheduledJobOption returns to set job options for a new or existing scheduled job. Alternatively, you can set job options by using the Get-ScheduledJobOption cmdlet to get the job options of an existing scheduled job or by using a hash table value to represent the job options. Without parameters, New-ScheduledJobOption generates an object that contains the default values for all of the options. Because all of the properties except for the JobDefinition property can be edited, you can use the resulting object as a template, and create standard option objects for your enterprise. When creating scheduled jobs and setting scheduled job options, review the default values of all scheduled job options. Scheduled jobs run only when all conditions set for their execution are satisfied. New-ScheduledJobOption 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-ScheduledJobOption [-RunElevated] [-HideInTaskScheduler] [-RestartOnIdleResume] [-MultipleInstancePolicy <TaskMultipleInstancePolicy>] [-DoNotAllowDemandStart] [-RequireNetwork] [-StopIfGoingOffIdle] [-WakeToRun] [-ContinueIfGoingOnBattery] [-StartIfOnBattery] [-IdleTimeout <TimeSpan>] [-IdleDuration <TimeSpan>] [-StartIfIdle] [<CommonParameters>]
Create a scheduled job option object with default values
New-ScheduledJobOptionIdentifyCreate a scheduled job option object with custom values
New-ScheduledJobOption -RequireNetwork -StartIfOnBatteryIdentifySet options for a new scheduled job
$runAsAdmin = New-ScheduledJobOption -RunElevated
$registerScheduledJobSplat = @{
Name = 'Backup'
FilePath = 'D:\Scripts\Backup.ps1'
Trigger = $Mondays
ScheduledJobOption = $RunAsAdmin
}
Register-ScheduledJob @registerScheduledJobSplat
Get-ScheduledJobOption -Name BackupIdentifySort the properties of a scheduled job option object
$options = New-ScheduledJobOption -WakeToRun
$options.psobject.Properties |
Sort-Object -Property Name |
Format-Table -Property Name, Value -AutoSizeIdentifyIts page in the reference: New-ScheduledJobOption.
Parameters
-ContinueIfGoingOnBatteryDo not stop the scheduled job if the computer switches to battery power (disconnects from AC power) while the job is running. By default, scheduled jobs stop when the computer disconnects from AC power.
The ContinueIfGoingOnBattery parameter sets the value of the StopIfGoingOnBatteries property of scheduled jobs to $true.-DoNotAllowDemandStartStart the job only when it is triggered. Users cannot start the job manually, such as by using the Run feature in Task Scheduler.
This parameter only affects Task Scheduler. It does not prevents users from using the Start-Job cmdlet to start the job.
The DoNotAllowDemandStart parameter sets the value of the DoNotAllowDemandStart property of scheduled jobs to $true.-HideInTaskSchedulerDo not display the job in Task Scheduler. This value affects only the computer on which the job runs. By default, scheduled tasks appear in Task Scheduler.
Even if a task is hidden, users can display the task by selecting the Show hidden tasks view option in Task Scheduler.
The HideInTaskScheduler parameter sets the value of the ShowInTaskScheduler property of scheduled jobs to $false.-IdleDurationSpecifies how long the computer must be idle before the job starts. The default value is 10 minutes. If the computer is not idle for the specified duration before the value of IdleTimeout expires, the scheduled job does not run until the next scheduled time, if any.
Enter a TimeSpan object, such as one generated by the New-TimeSpan cmdlet, or enter a value in <hours>:<minutes>:<seconds> format that is automatically converted to a TimeSpan object.
To enable this value, use the StartIfIdle parameter. By default, the StartIfNotIdle property of scheduled jobs is set to $true and Windows PowerShell ignores the IdleDuration and IdleTimeout values.-IdleTimeoutSpecifies how long the scheduled job waits for the computer to be idle. If this timeout expires before the computer remains idle for the time period that is specified by the IdleDuration parameter, the job does not run until the next scheduled time, if any. The default value is one hour.
Enter a TimeSpan object, such as one generated by the New-TimeSpan cmdlet, or enter a value in <hours>:<minutes>:<seconds> format that is automatically converted to a TimeSpan object.
To enable this value, use the StartIfIdle parameter. By default, the StartIfNotIdle property of scheduled jobs is set to $true and Windows PowerShell ignores the IdleDuration and IdleTimeout values.-MultipleInstancePolicyDetermines how the system responds to a request to start an instance of a scheduled job while another instance of the job is running. The default value is IgnoreNew. The acceptable values for this parameter are:
- IgnoreNew - The new job instance is ignored.
- Parallel - The new job instance starts immediately.
- Queue - The new job instance starts as soon as the current instance completes.
- StopExisting - The current instance of the job stops and the new instance starts.
To run the job, all conditions for the job schedule must be met. For example, if the conditions that are set by the RequireNetwork, IdleDuration, and IdleTimeout parameters are not satisfied, the job instance is not started, regardless of the value of this parameter.-RequireNetworkRuns the scheduled job only when network connections are available.
If you specify this parameter and the network is not available at the scheduled start time, the job does not run until the next scheduled start time, if any.
The RequireNetwork parameter sets the value of the RunWithoutNetwork property of scheduled jobs to $false.-RestartOnIdleResumeRestarts a scheduled job when the computer becomes idle. This parameter works with the StopIfGoingOffIdle parameter, which suspends a running scheduled job if the computer becomes active (leaves the idle state).
The RestartOnIdleResume parameter sets the value of the RestartOnIdleResume property of scheduled jobs to $true.-RunElevatedRuns the scheduled job with the permissions of a member of the Administrators group on the computer on which the job runs.
To enable a scheduled job to run with Administrator permissions, use the Credential parameter of
Register-ScheduledJob to provide explicit credential for the job.
The RunElevated parameter sets the value of the RunElevated property of scheduled jobs to
$true.-StartIfIdleStarts the scheduled job if the computer has been idle for the time specified by the IdleDuration parameter before the time specified by the IdleTimeout parameter expires.
By default, the IdleDuration and IdleTimeout parameters are ignored and the job starts at the scheduled start time even if the computer is busy.
If you specify this parameter and the computer is busy (not idle) at the scheduled start time, the job does not run until the next scheduled start time, if any.
The StartIfIdle parameter sets the value of the StartIfNotIdle property of scheduled jobs to
$false.-StartIfOnBatteryStarts the scheduled job even if the computer is running on batteries at the scheduled start time. The default value is $false.
The StartIfOnBattery parameter sets the value of the StartIfOnBatteries property of scheduled jobs to $true.-StopIfGoingOffIdleSuspends a running scheduled job if the computer becomes active (not idle) while the job is running.
By default, a scheduled job that is suspended when the computer becomes active resumes when the computer becomes idle again. To change this default behavior, use the RestartOnIdleResume parameter.
The StopIfGoingOffIdle parameter sets the value of the StopIfGoingOffIdle property of scheduled jobs to $true.-WakeToRunWakes the computer from a Hibernate or Sleep state at the scheduled start time so it can run the job. By default, if the computer is in a Hibernate or Sleep state at the scheduled start time, the job does not run.
The WakeToRun parameter sets the value of the WakeToRun property of scheduled jobs to
$true.