This script will loop through multiple msu windows updates files and install them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
############################################## # # Name: PrereqInstaller.ps1 # Version: v0.1 # Date: 3/13/2014 # Purpose: Install multiple Microsoft KB#### *.msu # Author: Randy Gray # # # Folder Structure # # source # ├-- PrereqInstaller.ps1 # ├-- Win7 # | ├-- x64 # | | | KBxxxxxxa # | | | └ Windows6.1-KBxxxxxxx-x64.msu # | | └ KBxxxxxxb # | | └ Windows6.1-KBxxxxxxx-x64.msu # | └-- x86 # | └ Windows6.1-KBxxxxxxx-x86.msu # └-- Win81 # ├-- x64 # | └ KBxxxxxxx # | └ Windows8.1-KBxxxxxxx-x64.msu # └-- x86 # └ Windows8.1-KBxxxxxxx-x86.msu # # # Variables # $path - directy scritpt was run from. # $msus - array of windows updates # $msu - current windows udpate # $update - array of file name spilt by '-' # $kbart - current update KB name # $Hotfix - result returned during installed check # $command - command to install update # $parameters - command plus the parameters to the install command '\quiet \norestart' # $install - process to start installation # $OS - Current OS version # #folder - current folder of under path that contains the udpates. # ############################################### function Install-MSU($path) { # get updates in folders $msus = ls -Path $path *.msu -Recurse # loop through updates foreach ($msu in $msus) { # spilt file name to get KB artical number $update = $msu.Name -Split'-' $kbart = $update[1] # check if update is already installed $HotFix = Get-HotFix -id $kbart -ea 0 # run if update is not installed if($HotFix -eq $null) { Write-Host "Installing $kbart" $command = "`"" + "$path\$msu" + "`"" $parameters = $command + "\quiet \norestart" $install = [System.Diagnostics.Process]::Start( "wusa",$parameters ) $install.WaitForExit() } # run if update is installed else { Write-Host "Update $kbart installed" } } } # set $path to current directory location $path = get-location # set $OS to current OS $OS = gwmi -query "select Caption, OSArchitecture from win32_OperatingSystem" # if OS is windows 7 if($OS.Caption -match 'Windows 7') { if($OS.OSArchitecture -match '64-bit') { $folder = 'win7\x64' $path = "$path\$folder" Install-MSU($path) } else { $folder = "win7\x86" $path = "$path\$folder" Install-MSU($path) } } # if OS is windows 8.1 elseif($OS.Caption -match 'Windows 8.1') { if($OS.OSArchitecture -match '64-bit') { $folder = 'win81\x64' $path = "$path\$folder" Install-MSU($path) } else { $folder = "win81\x86" $path = "$path\$folder" Install-MSU($path) } } else { } |