Task Scheduler is a built-in Windows facility for running PowerShell scripts on a schedule. It is easy to deploy and widely used, but lacks a central console, so task design, access, and maintenance require deliberate administration. section 3.2.1
Design scheduled tasks around these operational requirements:
- Run unattended by selecting an execution mode that does not require a user to remain logged on. section 3.2.1
- Check permissions for both the script file and every resource the script accesses. section 3.2.1
- Use a service account for scripts stored on network shares; never use a personal account whose password changes or account lockouts can interrupt the task. section 3.2.1
- Install required custom modules in a PowerShell module path that the scheduled process can access. section 3.2.1
- Separate watcher scripts, which monitor events, from action scripts, which perform the resulting work; define execution limits and graceful termination. section 3.5
Scheduled log cleanup
A task can invoke a reusable cleanup script with local or network paths, an archive prefix, and a retention period. The task identity must be able to read the script and access the log and archive locations. section 3.2.1
-File "C:\Scripts\Invoke-LogFileCleanup.ps1" -LogPath "L:\Logs\" -ZipPath "L: \Archives\" -ZipPrefix "LogArchive-" -NumberOfDays 30
Example PowerShell arguments for invoking a log-file cleanup script from a scheduled task. section 3.2.1
