CBC Computer Services

Use PowerShell to Manage & Download Windows Updates.

You can use PowerShell to manage and download Windows updates by leveraging the PSWindowsUpdate module, which provides cmdlets for managing updates. Here’s a step-by-step guide to install the module and use it to check for, download, and install updates.

Step 1: Install the PSWindowsUpdate Module

  1. Open PowerShell as Administrator.
  2. Run the following command to install the PSWindowsUpdate module:
   Install-Module -Name PSWindowsUpdate -Force -AllowClobber
  • -Force: Ensures the installation proceeds without prompts.
  • -AllowClobber: Allows the module to overwrite any existing cmdlets with the same name.

Step 2: Import the PSWindowsUpdate Module

After the module is installed, import it by running:

Import-Module PSWindowsUpdate

Step 3: Check for Available Updates

You can check for available updates by using the following command:

Get-WindowsUpdate

This command will list all available updates for the system but will not download or install them.

Step 4: Download and Install Updates

To download and install available updates, run:

Install-WindowsUpdate -AcceptAll -AutoReboot
  • -AcceptAll: Accepts all the available updates without prompting for confirmation.
  • -AutoReboot: Automatically restarts the system if required after updates are installed.

Step 5: Optional – Exclude Specific Updates

If you want to exclude certain updates (for example, driver updates), you can use the -NotCategory parameter. For instance, to exclude driver updates:

Install-WindowsUpdate -NotCategory "Drivers" -AcceptAll -AutoReboot

Step 6: Schedule Automatic Update Checks (Optional)

You can use Task Scheduler to run this script at regular intervals for automatic updates. Here’s a simple PowerShell script you can save as UpdateWindows.ps1:

# Import the PSWindowsUpdate module
Import-Module PSWindowsUpdate

# Check for updates and install them
Install-WindowsUpdate -AcceptAll -AutoReboot

Running the Script

  1. Open Notepad, paste the script, and save it as UpdateWindows.ps1.
  2. Run the script manually by opening PowerShell as Administrator and typing:
   .\UpdateWindows.ps1

Automating with Task Scheduler

  1. Open Task Scheduler.
  2. Click Create Task and set a name like “Windows Update Script.”
  3. Under Triggers, set when you want the script to run (e.g., daily, weekly).
  4. Under Actions, select Start a Program and enter:
  • Program/script: powershell.exe
  • Add arguments: -ExecutionPolicy Bypass -File "C:\Path\To\UpdateWindows.ps1"

Now, your system will automatically download and install updates based on the schedule you set.