-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoUpdateScript.ps1
37 lines (33 loc) · 1.07 KB
/
AutoUpdateScript.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
# Variables to be used by the update automation script.
$moduleInstall = "Install-Module -Name PSWindowsUpdate"
$prompt = "Would you like reboot afterwards? [y/n]"
$updateWithAutoReboot = "Get-WindowsUpdate -AcceptAll -Install -AutoReboot"
$updateWithoutAutoReboot = "Get-WindowsUpdate -AcceptAll -Install"
# Special arrays to make the process smoother.
$commandListWithReboot = @(
$moduleInstall
$updateWithAutoReboot
)
$commandListWithoutReboot = @(
$moduleInstall
$updateWithoutAutoReboot
)
# Definition of code to automate the update process. #
switch (Read-Host -Prompt $prompt) {
"y" {
if (Get-Module -Name PSWindowsUpdate) {
Start-Process powershell -Verb runas $updateWithAutoReboot
}
else {
Start-Process powershell -Verb runas $commandListWithReboot
}
}
"n" {
if (Get-Module -Name PSWindowsUpdate) {
Start-Process powershell -Verb runas $updateWithoutAutoReboot
}
else {
Start-Process powershell -Verb runas $commandListWithoutReboot
}
}
}