Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
Create a scheduled task using PowerShell.
February 20, 2015
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 "BUILTINAdministrators" -RunLevel "Highest"#Register the new scheduled taskRegister-ScheduledTask $STName -Action $STAction -Trigger $STTrigger -Principal $STPrincipal -Settings $STSettings
You May Also Like