New-Scheduled
Task
Principal
Syntax
New-ScheduledTaskPrincipal
[[-Id] <String>]
[[-RunLevel] <RunLevelEnum>]
[[-ProcessTokenSidType] <ProcessTokenSidTypeEnum>]
[[-RequiredPrivilege] <String[]>]
[-UserId] <String>
[[-LogonType] <LogonTypeEnum>]
[-CimSession <CimSession[]>]
[-ThrottleLimit <Int32>]
[-AsJob]
[<CommonParameters>]
New-ScheduledTaskPrincipal
[-GroupId] <String>
[[-Id] <String>]
[[-RunLevel] <RunLevelEnum>]
[[-ProcessTokenSidType] <ProcessTokenSidTypeEnum>]
[[-RequiredPrivilege] <String[]>]
[-CimSession <CimSession[]>]
[-ThrottleLimit <Int32>]
[-AsJob]
[<CommonParameters>]
Description
The New-ScheduledTaskPrincipal cmdlet creates an object that contains a scheduled task principal. Use a scheduled task principal to run a task under the security context of a specified account. When you use a scheduled task principal, Task Scheduler can run the task regardless of whether that account is logged on.
You can use the definition of a scheduled task principal to register a new scheduled task or update an existing task registration.
Examples
Example 1: Register a scheduled task by using a user ID for a task principal
PS C:\>$Sta = New-ScheduledTaskAction -Execute "Cmd"
The second command creates a scheduled task principal. The **New-ScheduledTaskPrincipal** cmdlet specifies that Task Scheduler uses the Local Service account to run tasks, and that the Local Service account uses the Service Account logon. The command assigns the **ScheduledTaskPrincipal** object to the $STPrin variable.
PS C:\>$STPrin = New-ScheduledTaskPrincipal -UserId "LOCALSERVICE" -LogonType ServiceAccount
The third command registers the scheduled task Task01 to run the task action named Cmd. The **Principal** parameter specifies that the Task Scheduler uses the Local Service account to run the task.
PS C:\>Register-ScheduledTask Task01 -Action $a -Principal $p
This example registers a scheduled task that will run as the Local Service account.
The first command creates a scheduled task action named Cmd and assigns the ScheduledTaskAction object to the $Sta variable.
Example 2: Register a scheduled task by using a user group for a task principal
PS C:\>$Sta = New-ScheduledTaskAction cmd
The second command creates a scheduled task principal. The **New-ScheduledTaskPrincipal** cmdlet specifies that Task Scheduler uses the Administrators user group that has the highest privileges to run tasks. The command assigns the **ScheduledTaskPrincipal** object to the $STPrin variable.
PS C:\>$STPrin = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest
The third command registers the scheduled task Task01 to run the task action named Cmd. The *Principal* parameter specifies that Task Scheduler uses the Administrators user group to run the task.
PS C:\>Register-ScheduledTask Task01 -Action $Sta -Principal $STPrin
This example registers a scheduled task that runs under logged-in members of the Administrators user group that has the highest privileges.
The first command creates a scheduled task action named cmd and assigns the ScheduledTaskAction object to the $Sta variable.
Required Parameters
Specifies the ID of a user group that Task Scheduler uses to run the tasks that are associated with the principal.
Type: | String |
Position: | 0 |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the user ID that Task Scheduler uses to run the tasks that are associated with the principal.
Type: | String |
Position: | 0 |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Optional Parameters
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 |
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 |
Specifies the ID of a scheduled task principal.
Type: | String |
Position: | 5 |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the security logon method that Task Scheduler uses to run the tasks that are associated with the principal. The acceptable values for this parameter are:
- None
- Password
- S4U
- Interactive
- Group
- ServiceAccount
- InteractiveOrPassword
Type: | LogonTypeEnum |
Parameter Sets: | None, Password, S4U, Interactive, Group, ServiceAccount, InteractiveOrPassword |
Position: | 1 |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the security ID (SID) type of the process token. The acceptable values for this parameter are:
- None
- Unrestricted
- Default
Type: | ProcessTokenSidTypeEnum |
Parameter Sets: | None, Unrestricted, Default |
Position: | 3 |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies an array of user rights that Task Scheduler uses to run the tasks that are associated with the principal. Specify the constant name that is associated with a user right.
Type: | String[] |
Position: | 4 |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the level of user rights that Task Scheduler uses to run the tasks that are associated with the principal. The acceptable values for this parameter are:
- Highest. Tasks run by using the highest privileges.
- Limited. Tasks run by using the least-privileged user account (LUA).
Type: | RunLevelEnum |
Parameter Sets: | Limited, Highest |
Position: | 2 |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
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 |
Outputs
Microsoft.Management.Infrastructure.CimInstance#MSFT_TaskPrincipal