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
- Run the Test it now line from the bottom of the script.
- Run the Check it line.
LastTaskResultshould be0. Any other number means the script failed or could not start.267009means it is still running. - 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.
Preview