What This Script Does

The setup-scheduled-tasks.ps1 script provides an interactive wizard for creating and managing Windows Scheduled Tasks that automate your Chocolatey maintenance routines. Instead of requiring you to manually open Task Scheduler, navigate its complex interface, and configure task settings by hand, this script walks you through the process with a series of clear prompts and sensible defaults. The result is a fully configured set of scheduled tasks that run your Chocolatey maintenance scripts automatically on the days and times you choose, without requiring any manual intervention.

When you launch the script, it presents you with a main menu offering several options: create new scheduled tasks, view existing Chocolatey-related tasks, modify existing tasks, remove tasks, or exit. This menu-driven approach makes the script accessible to users who are not familiar with the Windows Task Scheduler cmdlets or the Task Scheduler GUI. Each option leads to a focused sub-workflow that guides you through the specific operation with clear instructions and validation at every step.

The task creation workflow is the primary feature of the script. When you choose to create new tasks, the wizard first asks which maintenance scripts you want to schedule. The two most common choices are the auto-update script (auto-update-chocolatey.ps1) for keeping packages current, and the cleanup script (cleanup-chocolatey.ps1) for managing disk space. You can choose to schedule one or both of these scripts, and each one gets its own independently configured scheduled task with its own schedule settings.

For each task you create, the wizard walks you through selecting the schedule frequency and timing. You can choose from daily, weekly, or monthly schedules depending on how frequently you want the maintenance to run. For weekly schedules, you select which days of the week the task should run, with the ability to choose multiple days. For example, you might configure auto-updates to run on Sundays and Wednesdays, providing two update windows per week. For each selected schedule, you specify the time of day the task should execute. The wizard defaults to 3:00 AM, which is a common choice because most users are not actively using their computer at that hour, but you can select any time that works for your routine.

The recommended configuration for most users is to schedule auto-updates twice per week, on Sundays and Wednesdays at 3:00 AM, and to schedule cleanup monthly, on the first Sunday of each month at 4:00 AM. This configuration ensures that your packages are never more than a few days out of date while keeping cleanup operations infrequent enough to not impact system performance unnecessarily. The wizard presents these recommendations as defaults, so you can simply press Enter to accept them or type different values to customize the schedule to your preferences.

Behind the scenes, the script uses the Windows Task Scheduler PowerShell cmdlets to create the tasks with the correct configuration. Each task is configured to run with highest privileges (Administrator), which is required for Chocolatey operations. The tasks are set to run whether or not a user is logged in, ensuring that maintenance happens even if the machine is unattended. The script configures the tasks with the -ExecutionPolicy Bypass flag so that the PowerShell execution policy does not prevent the scheduled scripts from running. The task definitions point to the full absolute paths of the maintenance scripts, so they work correctly regardless of the working directory.

The view existing tasks feature provides a formatted display of all Chocolatey-related scheduled tasks currently configured on the system. For each task, it shows the task name, the current status (enabled or disabled), the next scheduled run time, the last run time and result, and the script that the task executes. This overview makes it easy to verify that your scheduled tasks are configured correctly and running as expected. If a task has failed on its last run, the display includes the error code and a brief description of what might have gone wrong.

The modify tasks option allows you to change the schedule of existing tasks without deleting and recreating them. You can adjust the days of the week, the time of day, or the frequency of execution. The modification workflow presents the current settings for the selected task and then walks you through changing whichever aspects you want to update. Settings you do not change retain their current values, so you can make a quick adjustment to the run time without having to re-enter the day and frequency settings.

The remove tasks option provides a safe way to delete scheduled tasks that are no longer needed. The script lists all Chocolatey-related tasks and lets you select which ones to remove. Before any task is deleted, the script asks for confirmation, displaying the full details of the task that will be removed. This confirmation step prevents accidental deletion of tasks that are still wanted, which could lead to packages going without updates or cleanup until the oversight is noticed.

The script includes validation logic throughout the wizard to prevent common configuration mistakes. If you enter an invalid time format, the wizard will prompt you again with guidance on the expected format. If you try to create a task that already exists, the script will warn you and offer to update the existing task instead. If the script directory path has changed since the tasks were originally created, the script detects this and offers to update the task definitions with the correct paths. These validations make the wizard robust against user error and environmental changes.

Creating scheduled tasks requires Administrator privileges because the tasks are configured to run at the system level with highest privileges. If the script detects that it is not running elevated, it displays a clear message explaining that Administrator privileges are required and provides instructions for running PowerShell as Administrator. This check happens before the main menu is displayed, so you know immediately if you need to restart with elevated privileges.

All task creation, modification, and removal operations are logged to %USERPROFILE%\Logs\ScheduledTaskSetup.log. The log records the full configuration of every task created or modified, including the script path, schedule settings, and run-as configuration. This log serves as a reference for the current state of your scheduled tasks and as an audit trail of changes made over time. If something goes wrong with a scheduled task, the setup log combined with the individual script logs provides a complete picture for troubleshooting.

Usage

Run the script from an elevated PowerShell window to launch the interactive wizard.

# Launch the scheduled tasks wizard (requires Administrator)
.\setup-scheduled-tasks.ps1

The wizard presents an interactive menu:

========================================
  Chocolatey Scheduled Tasks Setup
========================================

  1. Create new scheduled tasks
  2. View existing tasks
  3. Modify existing tasks
  4. Remove tasks
  5. Exit

Select an option (1-5):

Recommended Schedule

Task Script Frequency Time
Auto-Updateauto-update-chocolatey.ps1Sunday & Wednesday3:00 AM
Cleanupcleanup-chocolatey.ps1Monthly (1st Sunday)4:00 AM

What Gets Changed

  • Windows Scheduled Tasks — Creates, modifies, or removes entries in the Windows Task Scheduler for Chocolatey maintenance scripts.
  • Task permissions — Tasks are configured to run with highest privileges (Administrator) whether or not a user is logged in.
  • Task triggers — Schedule triggers are set based on your chosen frequency, days, and times.
  • Log file — Creates or appends to %USERPROFILE%\Logs\ScheduledTaskSetup.log.

Related Scripts