-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathOnlineUpdate.ps1
More file actions
136 lines (103 loc) · 7.37 KB
/
OnlineUpdate.ps1
File metadata and controls
136 lines (103 loc) · 7.37 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#*******************************************************************************
# Author: Mick Pletcher
# Date: 01 January 2014
#
# Program: Online Windows Updates Installer
#*******************************************************************************
#Declare Local Memory
Set-Variable -Name File -Scope Local -Force
Function DeclareGlobalMemory {
Set-Variable -Name Files -Scope Global -Force
Set-Variable -Name RelativePath -Scope Global -Force
}
Function GlobalMemoryCleanup {
Remove-Variable -Name Files -Scope Global -Force
Remove-Variable -Name RelativePath -Scope Global -Force
}
Function RenameWindow ($Title) {
#Declare Local Memory
Set-Variable -Name a -Scope Local -Force
$a = (Get-Host).UI.RawUI
$a.WindowTitle = $Title
#Cleanup Local Memory
Remove-Variable -Name a -Scope Local -Force
}
Function GetRelativePath {
$Global:RelativePath=(split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"
}
Function GetFiles {
$Global:Files = Get-ChildItem -Path $Global:RelativePath
}
Function CreateTempFolder ($FolderName) {
$FolderName = "c:\temp\"+$FolderName
New-Item -Path $FolderName -ItemType Directory -Force
}
Function RemoveTempFolder ($FolderName) {
$FolderName = "c:\temp\"+$FolderName
Remove-Item -Path $FolderName -Recurse -Force
}
Function ExtractCAB ($Name) {
#Declare Local Memory
Set-Variable -Name arguments -Scope Local -Force
Set-Variable -Name Dest -Scope Local -Force
Set-Variable -Name Source -Scope Local -Force
$Source = $Global:RelativePath+$Name
$Dest = "c:\temp\"+$Name.Substring(0,$Name.Length-4)
$arguments = "–F:*"+[char]32+$Source+[char]32+$Dest
Start-Process -FilePath "expand.exe" -ArgumentList $arguments -Wait -PassThru
#Cleanup Local Memory
Remove-Variable -Name arguments -Scope Local -Force
Remove-Variable -Name Dest -Scope Local -Force
Remove-Variable -Name Source -Scope Local -Force
}
#Function ApplyWindowsUpdate ($Name,$Directory) {
#
# #Declare Local Memory
# Set-Variable -Name arguments -Scope Local -Force
#
# $Name = $Name.Substring(0,$Name.Length-4)
# $Name = $Name+".cab"
# $arguments = "/Online /Add-Package /PackagePath:"+"c:\temp\"+$Directory+"\"+$Name
# Start-Process -FilePath "DISM.exe" -ArgumentList $arguments -Wait -PassThru
#
# #Cleanup Local Memory
# Remove-Variable -Name arguments -Scope Local -Force
#
#}
Function ApplyWindowsUpdate ($Name) {
#Declare Local Memory
Set-Variable -Name App -Scope Local -Force
Set-Variable -Name arguments -Scope Local -Force
Set-Variable -Name index -Scope Local -Force
Set-Variable -Name Result -Scope Local -Force
$App = $Name
$index = $App.IndexOf("-KB")+1
$App = $App.Substring(0,$App.Length-4)
$App = $App.Substring($index)
Write-Host "Installing"$App"....." -NoNewline
$arguments = $Global:RelativePath+$Name+[char]32+"/quiet /norestart"
$Result = (Start-Process -FilePath "wusa.exe" -ArgumentList $arguments -Wait -PassThru).ExitCode
If ($Result -eq "3010") {
Write-Host "Succeeded" -ForegroundColor Yellow
} else {
Write-Host "Failed with error code"$Result -ForegroundColor Red
}
#Cleanup Local Memory
Remove-Variable -Name App -Scope Local -Force
Remove-Variable -Name arguments -Scope Local -Force
Remove-Variable -Name index -Scope Local -Force
Remove-Variable -Name Result -Scope Local -Force
}
cls
RenameWindow "Windows Updates"
DeclareGlobalMemory
GetRelativePath
GetFiles
foreach ($File in $Files) {
if (($File.Attributes -ne "Directory") -and ($File.Name -like "*.msu")) {
ApplyWindowsUpdate $File.Name
}
}
GlobalMemoryCleanup
#Cleanup Local Memory
Remove-Variable -Name File -Scope Local -Force