Skip to main content
A PowerShell script that installs the PSWindowsUpdate module and applies all available Windows updates. Supports optional automatic reboot when kernel or driver updates require it.

Prerequisites

The script must be run in an elevated (Administrator) PowerShell session. Right-click PowerShell and select Run as Administrator, or open Windows Terminal as Administrator.

The Script

windows-update.ps1

Usage

:::caution If your PowerShell execution policy blocks scripts, you will need to allow it for the current session:
This only affects the current session and does not change the system-wide policy. :::

Scheduling with Task Scheduler

To run updates on a schedule:
  1. Open Task Scheduler (taskschd.msc)
  2. Create a new task with Run with highest privileges checked
  3. Set the trigger to your preferred schedule (e.g., weekly on Sundays at 3:00 AM)
  4. Set the action to:
    • Program: powershell.exe
    • Arguments: -ExecutionPolicy Bypass -File "C:\Scripts\windows-update.ps1"
Add -AutoReboot to the arguments if you want the server to reboot automatically after updates.

What PSWindowsUpdate Provides

The PSWindowsUpdate Module is a widely used community module that wraps the Windows Update Agent API. Key commands: