Export (0) Print
Expand All

New-ScheduledTaskPrincipal

Updated: October 30, 2012

Applies To: Windows Server 2012

New-ScheduledTaskPrincipal

Creates an object that contains a scheduled task principal.

Syntax

Parameter Set: User
New-ScheduledTaskPrincipal [-UserId] <String> [[-LogonType] <LogonTypeEnum> ] [[-RunLevel] <RunLevelEnum> ] [[-ProcessTokenSidType] <ProcessTokenSidTypeEnum> ] [[-RequiredPrivilege] <String[]> ] [[-Id] <String> ] [-AsJob] [-CimSession <CimSession[]> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]

Parameter Set: Group
New-ScheduledTaskPrincipal [-GroupId] <String> [[-RunLevel] <RunLevelEnum> ] [[-ProcessTokenSidType] <ProcessTokenSidTypeEnum> ] [[-RequiredPrivilege] <String[]> ] [[-Id] <String> ] [-AsJob] [-CimSession <CimSession[]> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]




Detailed 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.

Parameters

-AsJob

Runs the cmdlet as a background job. Use this parameter to run commands that take a long time to complete. The cmdlet immediately returns an object that represents the job and then displays the command prompt. You can continue to work in the session while the job completes. To manage the job, use the *-Job cmdlets. To get the job results, use the Receive-Job cmdlet. For more information about Windows PowerShell® background jobs, see about_Jobs.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-CimSession<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.


Aliases

Session

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-GroupId<String>

Specifies the ID of a user group that Task Scheduler uses to run the tasks that are associated with the principal.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Id<String>

Specifies the ID of a scheduled task principal.


Aliases

none

Required?

false

Position?

5

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-LogonType<LogonTypeEnum>

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


Aliases

none

Required?

false

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ProcessTokenSidType<ProcessTokenSidTypeEnum>

Specifies the security ID (SID) type of the process token. The acceptable values for this parameter are: None, Unrestricted, and Default.


Aliases

none

Required?

false

Position?

3

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-RequiredPrivilege<String[]>

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.


Aliases

none

Required?

false

Position?

5

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-RunLevel<RunLevelEnum>

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).


Aliases

none

Required?

false

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ThrottleLimit<Int32>

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.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-UserId<String>

Specifies the user ID that Task Scheduler uses to run the tasks that are associated with the principal.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters.

Outputs

The output type is the type of the objects that the cmdlet emits.

  • Microsoft.Management.Infrastructure.CimInstance#MSFT_TaskPrincipal

Examples

Example 1: Register a scheduled task by using a user ID for a task principal

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 -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

Example 2: Register a scheduled task by using a user group for a task principal

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.


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

Related topics

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft