This repository contains PowerShell scripts for automating system maintenance tasks on Windows, including package updates via Chocolatey and Windows Updates. The scripts are designed to be run at startup or on demand, with logging and administrative privilege escalation.
-
startup_script.ps1
Main script that:- Checks for and requests administrative privileges if needed.
- Logs all actions and output to a dated log file in a
logs
directory. - Upgrades all installed Chocolatey packages.
- Checks for and installs available Windows Updates using the
PSWindowsUpdate
module. - Cleans up log files older than 30 days.
-
schedule_task.ps1
Script to registerstartup_script.ps1
as a scheduled task that runs at user logon with highest privileges and a hidden window.
Open PowerShell 7+ as Administrator and run:
pwsh -File .\startup_script.ps1
Run the following command as Administrator to register the scheduled task:
pwsh -File .\schedule_task.ps1
This will ensure startup_script.ps1
runs automatically at every user logon.
- PowerShell 7 or later (
pwsh
) - Chocolatey package manager installed
- PSWindowsUpdate PowerShell module (installed automatically if missing)
- Administrative privileges to install updates and manage scheduled tasks
- Automatic Privilege Elevation: Prompts for admin rights if not already running as administrator.
- Comprehensive Logging: All actions and outputs are logged to timestamped files in a
logs
directory. - Chocolatey Updates: Automatically upgrades all Chocolatey packages.
- Windows Updates: Checks for and installs available Windows Updates.
- Log Maintenance: Deletes log files older than 30 days to save disk space.
- The script will not proceed if run in PowerShell versions older than 7.
- If Chocolatey is not installed, the script will prompt you to install it first.
- Windows Updates are installed non-interactively and will not automatically reboot the system.
- All logs are stored in a
logs
folder next to the script.
MIT License
Maintained by David Dashti. For questions or suggestions, please open an issue or contact me.