New-ScheduledTaskPrincipal
Creates an object that contains a scheduled task principal.
New-ScheduledTaskPrincipal
[-UserId] <String>
[[-LogonType] <LogonTypeEnum>]
[[-RunLevel] <RunLevelEnum>]
[[-ProcessTokenSidType] <ProcessTokenSidTypeEnum>]
[[-RequiredPrivilege] <String[]>]
[[-Id] <String>]
[-AsJob]
[-CimSession <CimSession[]>]
[-ThrottleLimit <Int32>]
New-ScheduledTaskPrincipal
[-GroupId] <String>
[[-RunLevel] <RunLevelEnum>]
[[-ProcessTokenSidType] <ProcessTokenSidTypeEnum>]
[[-RequiredPrivilege] <String[]>]
[[-Id] <String>]
[-AsJob]
[-CimSession <CimSession[]>]
[-ThrottleLimit <Int32>]
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.
The first command creates a scheduled task action named Cmd and assigns the **ScheduledTaskAction** object to the Sta variable.
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.
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.
ps_cimcommon_asjob
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
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-CimSessionhttp://go.microsoft.com/fwlink/p/?LinkId=227967 or Get-CimSessionhttp://go.microsoft.com/fwlink/p/?LinkId=227966 cmdlet. The default is the current session on the local computer.
Type: | CimSession[] |
Aliases: | Session |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the ID of a user group that Task Scheduler uses to run the tasks that are associated with the principal.
Type: | String |
Position: | 1 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the ID of a scheduled task principal.
Type: | String |
Position: | 6 |
Default value: | None |
Required: | False |
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
- Interactive or Password
Type: | LogonTypeEnum |
Position: | 2 |
Default value: | None |
Required: | False |
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, and Default.
Type: | ProcessTokenSidTypeEnum |
Position: | 4 |
Default value: | None |
Required: | False |
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: | 5 |
Default value: | None |
Required: | False |
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.
- LUA: Tasks run by using the least-privileged user account (LUA).
Type: | RunLevelEnum |
Position: | 3 |
Default value: | None |
Required: | False |
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 |
Required: | False |
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: | 1 |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |