Skip navigation

Create a Scheduled Task Using PowerShell

Create a scheduled task using PowerShell.

Q. How can I create a scheduled task that runs at startup using PowerShell?

A. To create a scheduled task using PowerShell, the following can be used. (Note the PowerShell window will need to run with elevated privileges.):

#Create a new trigger that is configured to trigger at startup
$STTrigger = New-ScheduledTaskTrigger -AtStartup
#Name for the scheduled task
$STName = "Running Task 1"
#Action to run as
$STAction = New-ScheduledTaskAction -Execute "image.exe"
#Configure when to stop the task and how long it can run for. In this example it does not stop on idle and uses the maximum possible duration by setting a timelimit of 0
$STSettings = New-ScheduledTaskSettingsSet -DontStopOnIdleEnd -ExecutionTimeLimit ([TimeSpan]::Zero)
#Configure the principal to use for the scheduled task and the level to run as
$STPrincipal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel "Highest"
#Register the new scheduled task
Register-ScheduledTask $STName -Action $STAction -Trigger $STTrigger -Principal $STPrincipal -Settings $STSettings

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish