When starting their PowerShell automation journey, one of the first things everyone wants to learn about is scheduling scripts to run unattended. In this chapter, you will learn more than just how to schedule a script. You will also learn some best practices, using common real-world scenarios that will help to ensure your scheduled scripts run smoothly. The concepts and practices used in these examples can be applied to any script you need to schedule.
It is tempting to say that you can take any existing PowerShell script and schedule it with a job scheduler, but that is only part of the solution. Before jumping straight into scheduling a PowerShell script, you must ensure that your script is adequately written to handle being run unattended. This includes many of the previously covered concepts, like ensuring dependencies are met and there are no user prompts.
There are several different types of scripts you will want to run on a scheduled basis. Two of the most common are scheduled scripts and watcher scripts. A scheduled script is any script that runs on a regular basis but not so often that it is continuously running. A watcher script runs either continuously or at least every few minutes. This chapter will cover both types, including the factors to consider when coding them and the considerations to make when scheduling them.