-
Notifications
You must be signed in to change notification settings - Fork 128
/
InstallOnlineUpdates.ps1
88 lines (80 loc) · 3.32 KB
/
InstallOnlineUpdates.ps1
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
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.99
Created on: 1/18/2016 1:41 PM
Created by: Mick Pletcher
Filename: InstallOnlineUpdates.ps1
===========================================================================
.DESCRIPTION
This script will install both exe updates and msu updates. It is
intended to be used during the generation of a reference image. Not
all updates can be injected offline into the OS. This script takes
care of those by running post-OS install.
#>
function Install-EXEUpdates {
#Declare Variables
Set-Variable -Name Arguments -Scope Local -Force
Set-Variable -Name ErrCode -Scope Local -Force
Set-Variable -Name File -Scope Local -Force
Set-Variable -Name EXEFiles -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
$RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + "\"
$EXEFiles = Get-ChildItem -Path $RelativePath -Force | where { $_.Name -like "*.exe*" }
If ($EXEFiles.Count -ge 1) {
$EXEFiles | Sort-Object
cls
foreach ($File in $EXEFiles) {
$Arguments = "/passive /norestart"
Write-Host "Installing"$File.Name"....." -NoNewline
$ErrCode = (Start-Process -FilePath $File.Fullname -ArgumentList $Arguments -Wait -Passthru).ExitCode
If ($ErrCode -eq 0) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed with error code"$ErrCode -ForegroundColor Red
}
}
}
#Cleanup Local Variables
Remove-Variable -Name Arguments -Scope Local -Force
Remove-Variable -Name ErrCode -Scope Local -Force
Remove-Variable -Name File -Scope Local -Force
Remove-Variable -Name EXEFiles -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
}
function Install-MSUUpdates {
#Declare Variables
Set-Variable -Name Arguments -Scope Local -Force
Set-Variable -Name ErrCode -Scope Local -Force
Set-Variable -Name Executable -Value $env:windir"\System32\wusa.exe" -Scope Local -Force
Set-Variable -Name File -Scope Local -Force
Set-Variable -Name MSUFiles -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
$RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + "\"
$MSUFiles = Get-ChildItem -Path $RelativePath -Force | where { $_.Name -like "*.msu*" }
If ($MSUFiles.Count -ge 1) {
$MSUFiles | Sort-Object
cls
foreach ($File in $MSUFiles) {
$Arguments = $File.FullName + [char]32 + "/quiet /norestart"
Write-Host "Installing"$File.Name"....." -NoNewline
$ErrCode = (Start-Process -FilePath $Executable -ArgumentList $Arguments -Wait -Passthru).ExitCode
If (($ErrCode -eq 0) -or ($ErrCode -eq 2359302)) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed with error code"$ErrCode -ForegroundColor Red
}
}
}
#Cleanup Local Variables
Remove-Variable -Name Arguments -Scope Local -Force
Remove-Variable -Name ErrCode -Scope Local -Force
Remove-Variable -Name Executable -Scope Local -Force
Remove-Variable -Name File -Scope Local -Force
Remove-Variable -Name MSUFiles -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
}
cls
Install-EXEUpdates
Install-MSUUpdates
Start-Sleep -Seconds 5