Home > Useful Tools > Script to Install Multiple Windows Updates or Hotfixes

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”

Advertisements
Categories: Useful Tools Tags:
  1. September 6, 2012 at 4:17 pm

    Great post. Very helpful. Thanks for the info.

  2. May 22, 2013 at 3:15 pm

    I need a away to do this with out redirects. I cant use %%A or %%B. any way to do this through a alternate methode

    • May 22, 2013 at 3:17 pm

      I am using PSexuc this on another PC with in my network.

  3. Clampatron
    October 18, 2013 at 12:02 pm

    Download MSU files manually from microsoft download centre.

    Extract the cab files using:
    Extract -F:*

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

  4. Clampatron
    October 18, 2013 at 12:03 pm

    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]

  5. Tim Howard
    November 18, 2015 at 9:10 pm

    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!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: