-
Notifications
You must be signed in to change notification settings - Fork 0
/
updgui.ps1
165 lines (156 loc) · 7.98 KB
/
updgui.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
$Button3_Click = {
. (Join-Path $PSScriptRoot 'aboutform.designer.ps1')
$AboutForm.ShowDialog($Form1)
}
$ListView1_ItemChecked = {
if ($ListView1.CheckedItems.Count -gt 0) {
$Button2.Enabled = $true
} else {
$Button2.Enabled = $false
}
}
$ListView1_SelectedIndexChanged = {
if ($ListView1.CheckedItems.Count -gt 0) {
$Button2.Enabled = $true
} else {
$Button2.Enabled = $false
}
}
$Button2_Click = {
# Install selected updates
if ($ListView1.CheckedItems.Count -gt 0) {
$CheckBox1.Enabled = $false
$Label1.Visible = $true
Invoke-InfoLogging "Installing selected updates. Please wait..."
Invoke-InfoLogging "While you're waiting, why not listen to some cheerful music? https://www.youtube.com/watch?v=QHdZjxrG35U"
$checkedUpdates = $ListView1.CheckedItems
foreach ($selLVI in $checkedUpdates) {
Invoke-InfoLogging "Installing update with name: `"$($selLVI.SubItems[4].Text)`" (KB Article ID: $($selLVI.SubItems[2].Text))..."
if ($selLVI.Subitems[2].Text -ne "") {
if ($CheckBox1.Checked -eq $true) {
Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false -Verbose
} else {
Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false
}
} else {
if ($CheckBox1.Checked -eq $true) {
Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false -Verbose
} else {
Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false
}
}
if ($?) {
Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has been successfully installed"
$ListView1.Items.Remove($selLVI)
} else {
Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has not been installed"
Invoke-InfoLogging "Error information: $_.Exception.Message"
}
}
$Label1.Visible = $false
$CheckBox1.Enabled = $true
} else {
[System.Windows.Forms.MessageBox]::Show("Please select updates to install and try again.")
}
}
$Form1_FormClosed = {
}
$Form1_FormClosing = {
}
$Button1_Click = {
$ListView1.Items.Clear()
# Get Windows Updates
Invoke-InfoLogging "Getting Windows updates. Please wait..."
$availableUpdates = Get-WindowsUpdates
Invoke-InfoLogging "Available updates: $($availableUpdates.Count)"
if ($availableUpdates.Count -gt 0) {
Invoke-InfoLogging "Displaying updates..."
for ($i = 0; $i -lt $availableUpdates.Count; $i++) {
$ListView1.Items.Add([System.Windows.Forms.ListViewItem]::new([string[]]@(
"",
$availableUpdates[$i].ComputerName,
$availableUpdates[$i].KB,
$availableUpdates[$i].Size,
$availableUpdates[$i].Title
)))
}
} else {
Invoke-InfoLogging "Your system is up to date."
[System.Windows.Forms.MessageBox]::Show("Your system is up to date.")
}
}
function Get-WindowsUpdates {
return Get-WindowsUpdate
}
function Invoke-InfoLogging {
param (
[Parameter(Mandatory, Position = 0)] [string] $message
)
Write-Host "[$(Get-Date)] $message"
}
function Check-PSWindowsUpdate {
try {
Invoke-InfoLogging "Checking PSWindowsUpdate..."
if ((Get-Module -Name PSWindowsUpdate -ListAvailable).Count -lt 1) {
Invoke-InfoLogging "PSWindowsUpdate not detected. Installing..."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module PSWindowsUpdate -Force
if ((Get-Module -Name PSWindowsUpdate -ListAvailable).Count -lt 1) { throw }
}
if ((Get-Module -Name PSWindowsUpdate).Count -lt 1) {
Invoke-InfoLogging "PSWindowsUpdate not imported. Importing..."
Import-Module PSWindowsUpdate
if ((Get-Module -Name PSWindowsUpdate).Count -lt 1) { throw }
}
Invoke-InfoLogging "Either the PSWindowsUpdate module has been successfully imported or no actions had to be done in the first place. Continuing startup..."
}
catch {
Invoke-InfoLogging "Unable to check PSWindowsUpdate. Error: $($_.Exception.Message). Exiting..."
exit 1
}
}
function Show-StartupGraphic {
# Show a cool graphic on startup
Write-Host -NoNewline "`n`n"
Write-Host " dddddddd "
Write-Host " UUUUUUUU UUUUUUUU d::::::d GGGGGGGGGGGGGUUUUUUUU UUUUUUUUIIIIIIIIII"
Write-Host " U::::::U U::::::U d::::::d GGG::::::::::::GU::::::U U::::::UI::::::::I"
Write-Host " U::::::U U::::::U d::::::d GG:::::::::::::::GU::::::U U::::::UI::::::::I"
Write-Host " UU:::::U U:::::UU d:::::d G:::::GGGGGGGG::::GUU:::::U U:::::UUII::::::II"
Write-Host " U:::::U U:::::Uppppp ppppppppp ddddddddd:::::d G:::::G GGGGGG U:::::U U:::::U I::::I "
Write-Host " U:::::D D:::::Up::::ppp:::::::::p dd::::::::::::::dG:::::G U:::::D D:::::U I::::I "
Write-Host " U:::::D D:::::Up:::::::::::::::::p d::::::::::::::::dG:::::G U:::::D D:::::U I::::I "
Write-Host " U:::::D D:::::Upp::::::ppppp::::::pd:::::::ddddd:::::dG:::::G GGGGGGGGGG U:::::D D:::::U I::::I "
Write-Host " U:::::D D:::::U p:::::p p:::::pd::::::d d:::::dG:::::G G::::::::G U:::::D D:::::U I::::I "
Write-Host " U:::::D D:::::U p:::::p p:::::pd:::::d d:::::dG:::::G GGGGG::::G U:::::D D:::::U I::::I "
Write-Host " U:::::D D:::::U p:::::p p:::::pd:::::d d:::::dG:::::G G::::G U:::::D D:::::U I::::I "
Write-Host " U::::::U U::::::U p:::::p p::::::pd:::::d d:::::d G:::::G G::::G U::::::U U::::::U I::::I "
Write-Host " U:::::::UUU:::::::U p:::::ppppp:::::::pd::::::ddddd::::::dd G:::::GGGGGGGG::::G U:::::::UUU:::::::U II::::::II"
Write-Host " UU:::::::::::::UU p::::::::::::::::p d:::::::::::::::::d GG:::::::::::::::G UU:::::::::::::UU I::::::::I"
Write-Host " UU:::::::::UU p::::::::::::::pp d:::::::::ddd::::d GGG::::::GGG:::G UU:::::::::UU I::::::::I"
Write-Host " UUUUUUUUU p::::::pppppppp ddddddddd ddddd GGGGGG GGGG UUUUUUUUU IIIIIIIIII"
Write-Host " p:::::p "
Write-Host " p:::::p "
Write-Host " p:::::::p "
Write-Host " p:::::::p "
Write-Host " p:::::::p "
Write-Host " ppppppppp "
Write-Host -NoNewline "`n`n"
Write-Host " A simple front-end for PSWindowsUpdate. "
Write-Host " Version 1.0 "
Write-Host " Programming: https://www.github.com/CodingWonders "
Write-Host " Idea: https://www.github.com/og-mrk "
Write-Host ""
Write-Host " ASCII graphic: http://patorjk.com/software/taag "
Write-Host ""
}
Clear-Host
# Set execution policy for the process scope
Set-ExecutionPolicy Bypass Process
Show-StartupGraphic
Check-PSWindowsUpdate
Add-Type -AssemblyName System.Windows.Forms
. (Join-Path $PSScriptRoot 'updgui.designer.ps1')
$Form1.ShowDialog() | Out-Null
Clear-Host