Powershell script to install Windows Updates from folder

By | December 17, 2010

 

If you’ve been working with Exchange 2010 Service Pack 1 you will know that there are several pre-requisites to download and install. Once downloaded you end up with a bunch of *.msu (Windows Update) files.  If, like me, you have to install them on several servers and don’t like the idea of having to double-click to install them via the UI you look for ways to simplify the process.  Powershell struck me as the obvious solution, but I couldn’t find any cmdlets that manage Windows Updates.  There are some examples, such as this from James O’Neill, but which are somewhat too elaborate for what I wanted to do.  In the end I wrote a small script (below) that calls wusa.exe to install the updates.  Not the prettiest method.  Hopefully Microsoft will provide set of cmdlets to manage Windows Updates in the next version of Windows.

#########################################################
#
# Name: InstallWindowsUpdates.ps1
# Author: Tony Murray
# Version: 1.0
# Date: 16/11/2010
# Comment: PowerShell script to install 
# Windows Update files
#
#########################################################

# Specify the location of the *.msu files
$updatedir = "C:\E2010 SP1 Prereqs\"
###

$files = Get-ChildItem $updatedir -Recurse
$msus = $files | ? {$_.extension -eq ".msu"}

foreach ($msu in $msus)
{
    write-host "Installing update $msu ..."
    $fullname = $msu.fullname
    # Need to wrap in quotes as folder path may contain spaces
    $fullname = "`"" + $fullname + "`""
    # Specify the command line parameters for wusa.exe
    $parameters = $fullname + " /quiet /norestart"
    # Start wusa.exe and pass in the parameters
    $install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
    $install.WaitForExit()
    write-host "Finished installing $msu"
}

write-host "Restarting Computer"
#Restart-Computer

If someone has a better method for doing this, please let me know.

6 thoughts on “Powershell script to install Windows Updates from folder

  1. Wyatt75

    Hello!

    Anybody knows how can I include in the Script the IE11 installation, and wait the installion patches until IE11 is installed on the computer.

    I’m triying with parameters below, but installation of IE and hotfixes start at the same time.

    COMMAND

    Start-Process C:\E2010 SP1 Prereqs\IE11-Windows6.1-x86-en-us.exe” -ArgumentList “/closeprograms”, “/passive”, “update-no”, /norestart”

    PARAMETERS

    – Out-Null,
    – Start-Process -NoNewWindow -Wait
    – $proc = Start-Process -NoWindow $proc.WaitForExit()

    Thanks!

    Reply
  2. Charles

    Wyatt75, if you place -Wait at the end of the line you should be fine.

    Start-Process C:\E2010 SP1 Prereqs\IE11-Windows6.1-x86-en-us.exe” -ArgumentList “/closeprograms”, “/passive”, “update-no”, /norestart” -Wait

    Reply

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.