New-ScheduledTask

Creates a scheduled task instance.

Syntax

New-ScheduledTask
   [[-Action] <CimInstance[]>]
   [[-Trigger] <CimInstance[]>]
   [[-Settings] <CimInstance>]
   [[-Principal] <CimInstance>]
   [[-Description] <String>]
   [-AsJob]
   [-CimSession <CimSession[]>]
   [-ThrottleLimit <Int32>]

Description

The New-ScheduledTask cmdlet creates an object that contains the definition of a scheduled task. New-ScheduledTask does not automatically register the object with the Task Scheduler service.

You can register a task to run any of the following application or file types: Win32 applications, Win16 applications, OS/2 applications, MS-DOS applications, batch files (.bat), command files (.cmd), or any properly registered file type.

Examples

Example 1: Define a scheduled task and register it at a later time

PS C:\> $A = New-ScheduledTaskAction -Execute "Taskmgr.exe" PS C:\>$T = New-ScheduledTaskTrigger -AtLogon PS C:\>$P = "Contoso\Administrator" PS C:\>$S = New-ScheduledTaskSettingsSet PS C:\>$D = New-ScheduledTask -Action $A -Principal $P -Trigger $T -Settings $S PS C:\>Register-ScheduledTask T1 -InputObject $D

In this example, the set of commands uses several cmdlets and variables to define and then register a scheduled task.

The first command uses the New-ScheduledTaskAction cmdlet to assign the executable file tskmgr.exe to the variable $A.

The second command uses the New-ScheduledTaskTrigger cmdlet to assign the value AtLogon to the variable $T.

The third command assigns the principal of the scheduled task Contoso\Administrator to the variable $P.

The fourth command uses the New-ScheduledTaskSettingsSet cmdlet to assign a task settings object to the variable $S.

The fifth command creates a new task and assigns the task definition to the variable $D.

The sixth command (hypothetically) runs at a later time. It registers the new scheduled task and defines it by using the $D variable.

Parameters

-Action

Specifies an array of work items for a task to run. When you specify multiple actions, they run sequentially. A task can have up to 32 actions.

Type:CimInstance[]
Position:1
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-AsJob

Runs the cmdlet as a background job. Use this parameter to run commands that take a long time to complete.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-CimSession

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.

Type:CimSession[]
Aliases:Session
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Description

Briefly describes the task.

Type:String
Position:5
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Principal

Specifies the security context in which a task runs.

Type:CimInstance
Position:4
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Settings

Specifies a configuration object that the Task Scheduler service uses to determine how to run a task.

Type:CimInstance
Position:3
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ThrottleLimit

Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.

Type:Int32
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Trigger
Type:CimInstance[]
Position:2
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Outputs

CimInstance