Skip to content
Menu

Install Windows Updates

Installs security and critical Windows updates through the Windows Update Agent, one row each, with excluded KBs and an optional restart when nobody is signed in.

Install Windows updates is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Install Windows updates. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1, administrator rights, Windows Update service, a reachable update source
Changes thingsChanges what it runs on

What It Does

The script uses the Windows Update Agent, the same engine as Windows Update, so it follows the PC's own update source, whether Microsoft, WSUS or Windows Update for Business policy. It searches for software updates that are not installed and not hidden, keeps the ones in Categories, drops ExcludeKBs, then downloads and installs them one at a time, one row each. It accepts the licence terms of the updates it installs, and an update that needs a person to answer a prompt is skipped and said so.

Categories are Security, which includes the monthly cumulative updates, Critical, or All. The default is Security and Critical. Feature updates, which are Windows version upgrades, are never installed by this script, and drivers are left alone unless IncludeDrivers is true.

One failing update does not stop the others. If a restart was already pending, updates fail and none were left unstarted due to the time limit, the run reports SKIPPED and asks you to restart and try again. Otherwise it names the failures as an error. When TimeoutMinutes has passed, it stops starting new updates and reports how many are left.

When Windows needs a restart, the script schedules one in 60 seconds only if RebootIfRequired is true and nobody is signed in. Otherwise it reports that a restart is needed.

Before You Run It

  • Run it with DryRun=true first and read the list of updates it would install.
  • Schedule it outside working hours. Updates can take a long time and some need a restart.
  • Use ExcludeKBs for an update you know causes trouble for this client.
  • Leave RebootIfRequired off unless a restart when nobody is signed in is acceptable.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
  • What it changes: Installs Windows updates; may restart the PC when RebootIfRequired is true and nobody is signed in.
  • Restart: It restarts the machine itself: that is its job, or an input you set turns it on. The answer says when.
  • Typical run: 5 to 120 minutes.
  • Example answer: "Installed 3 updates (KB5044284, KB5043145, KB5041587); reboot needed"
  • Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • Categories: Which updates to install, comma or semicolon separated: Security, Critical, All. Default Security,Critical.
  • IncludeDrivers: true to also install pending driver updates. Default false.
  • ExcludeKBs: KB numbers never to install, comma or semicolon separated, with or without the KB prefix. Default empty.
  • RebootIfRequired: true to restart the PC when updates need it and nobody is signed in. Default false.
  • TimeoutMinutes: No new update is started after this many minutes. Whole number, 5 to 1440. Default 120.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

install-windows-updates.ps1 · 1005 lines · 51.1 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.