Builders

Builder

Run a script on a schedule

Generate a Register-ScheduledTask command that runs a .ps1 daily, weekly, or at sign-in.

Creates a Windows scheduled task that runs your script with Windows PowerShell, in the background with no window. The task runs as you, only while you are signed in. If the PC is off or asleep at the scheduled time, it runs as soon as the PC is back.

Check that it worked

  1. Run the Test it now line from the bottom of the script.
  2. Run the Check it line. LastTaskResult should be 0. Any other number means the script failed or could not start. 267009 means it is still running.
  3. If it failed, run the script by hand in a new PowerShell window and read the error.

Test the script by hand first. If it works at the prompt but not on the schedule, the usual cause is a relative path inside the script. Scheduled tasks start in C:\Windows\System32, not in your folder.

Run it even when you are signed out

Open Task Scheduler, find the task under Task Scheduler Library, open Properties, and choose Run whether user is logged on or not. Windows asks for your password and stores it for the task. Network drives mapped to your account are not available in that mode, so use full \\server\share paths in the script.

Shows up in Task Scheduler. Pick something you will recognize later.

Use a full path. Scheduled tasks do not start in your current folder.

Typed exactly as you would after the script name.

Preview

scheduled-task.ps1