Script to Install Multiple Windows Updates or Hotfixes

I have been plagued for a while, as I am sure you have with the shear amount of patches,hotfixes and other bits of software I have needed to install on my Hyper-V host clusters, I recently got myself into a little bit of trouble when one of my cluster had one missing so today I set about finding a script that would silently install all the required patches and hotfixes. I thought this would be a simple search of the web where someone would have already hit this problem and have shared their code I was surprised there were loads of web sites with scripts and PowerShell examples to work with Windows Updates or WSUS servers but this is not what I was after. What I wanted was a script to automatically and dynamically install patches in a folder which meant I did not need to keep this script up to date. I came across this site where there was a great post showing multiple examples of achieving this.

Below is the code I have settled on, this will enumerate all the patches and hotfixes in the folder the batch file is executed from and it will enumerate the subfolders (nice).

It would be nice if I have the time to expand the script to do lots more, so if I manage to get that done I will share my changes. But you never know with Server 2012 I may not need to worry about this but we will see….

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /R “%~dp0” %%A IN (*-KB*.MSU) DO (
CALL :SUB %%~nA
ECHO= Installing KB!KB_NUM!
>NUL TIMEOUT /t 3
WUSA “%%A” /quiet /norestart)
ECHO= == Press any key to restart ==
>NUL PAUSE
SHUTDOWN.EXE /r /t 0
GOTO :EOF

:SUB
SET “KB_NUM=%*”
FOR /F “DELIMS=-” %%B IN (“%KB_NUM:*-KB=%”) DO SET “KB_NUM=%%B”

6 thoughts on “Script to Install Multiple Windows Updates or Hotfixes

  1. Download MSU files manually from microsoft download centre.

    Extract the cab files using:
    Extract -F:*

    Install using DISM using:
    DISM /online /add-package /packagepath:

  2. Download MSU files manually from microsoft download centre.

    Extract the cab files using:
    Extract -F:* [MSUs folder\*] [CAB destination folder]

    Install using DISM using:
    DISM /online /add-package /packagepath:[CAB destination folder]

  3. Just a note I discovered. Path names that are deep and have spaces seem to trip this up. However I can’t remember if this was before or after I changed the quotes to the standard ones for code. The ones above will not cut and paste and then run – it gave an error. Also the original install files seem to be happier in the same file as the script. Other than that… a great script!

Leave a comment