-
Notifications
You must be signed in to change notification settings - Fork 0
/
wup.ps1
44 lines (35 loc) · 1.06 KB
/
wup.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
# Check if PSWindowsUpdate module is installed
$moduleInstalled = Get-Module -Name PSWindowsUpdate -ListAvailable
# If not installed, install the module
if (-not $moduleInstalled) {
echo "Installing module"
Install-Module -Name PSWindowsUpdate -Force -AllowClobber
}
# Import the module
Import-Module PSWindowsUpdate
# Configure update settings
$UpdateSettings = @{
AutoSelectUpdates = $true
DownloadOnly = $false
InstallUpdates = $true
AcceptAll = $true
}
# Get the list of pending updates
$Updates = Get-WUList
# Filter updates by classification (Critical and Security)
$FilteredUpdates = Get-WindowsUpdate -Severity Critical
# Check if filtered updates are available
if ($FilteredUpdates.Count -eq 0) {
echo "Device is up-to-date"
Exit
}
# Install filtered updates
echo "Installing..."
Install-WUUpdates @UpdateSettings -Updates $FilteredUpdates
echo "Success. Reboot required"
# If a reboot is required, display a message
if (Get-WURebootStatus -eq 'RebootPending') {
echo "Reboot required"
} else {
echo "Dev update completed"
}