How To Install Multiple MSU Windows Update Files With PowerShell Script

Keeping Windows up to date is critical from security point of view. Each month on second Tuesday (aka ‘patch Tuesday’) Microsoft issues critical and recommended security updates and bug fixes which everyone should install. But if you are on a low-bandwidth Internet connection (or none at all), you may grab the updates from Microsoft Download Center and install the msu files manually. However, depending on the number of updates released or for how long you haven’t been installing updates, the number of files to install may grow above 30. To install all these files in a seamless way without any intervention you can harness the power of PowerShell – Windows’ own shell, just like Bash in Linux.

For this you need a small script which you need to run from an elevated PowerShell instance. Here is the script –

$dir = (Get-Item -Path ".\" -Verbose).FullName
 Foreach($item in (ls $dir *.msu -Name))
 {
	echo $item
	$item = $dir + "\" + $item
	wusa $item /quiet /norestart | Out-Null
 }
 

Create a file named “install.ps1” (or any other name with .ps1 as extension) in the directory where all your msu files are present and paste this script into it. Open an elevated (run as Administrator) instance of PowerShell and navigate to the directory where the msu files are located (using cd command). Type “.\install.ps1” (this may change depending on what you named your file as) and press enter. It will now install one file at a time and display the name of file currently being installed.

Untitled

If you get an error like this – “… cannot be loaded because the execution of scripts is disabled on this system”;

error

run this command and try running the script again –

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

This will enable running of scripts on your computer and you can continue with installing Windows updates.

20 thoughts on “How To Install Multiple MSU Windows Update Files With PowerShell Script

    1. Stick this at the top of the install script to extract the MSU’s first:

      if (Test-Path -Path “.\*.zip”)
      {
      $dir = (Get-Item -Path “.\” -Verbose).FullName
      Foreach($item in (ls $dir *.zip -Name))
      {
      Expand-Archive $item -DestinationPath “.\”
      Remove-Item $item
      }
      }

      Like

  1. Hi Harshil
    Does this Script install order is one by one or random? and what if the files are in share folder(other server)?
    Thanks in advance

    Like

  2. Hi. Could it be divorced? What file install.ps1? Is it a folder? What directory is this folder? How can I put the script somewhere? I thought I should put it in PowerShell. What does the CD command look like?

    Like

Leave a comment