Skip to content

Commit

Permalink
Update check_windows_updates.ps1
Browse files Browse the repository at this point in the history
Changes to solve the situation when updates are installed but status is still WARNING with waiting updates
  • Loading branch information
SpadeEagle44 authored Oct 14, 2023
1 parent 05ae90f commit 32c6f6b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions check_windows_updates.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<#
.VERSION
1.3.0
1.4.0
.AUTOR
.AUTHOR
John Gonzalez
#>

$script = "check_windows_updates.ps1"
$version = "1.3.0"
$version = "1.4.0"
$author = "John Gonzalez"

if ($args.Contains("-v")) {
Expand All @@ -19,18 +19,18 @@ if ($args.Contains("-v")) {
$updateSession = New-Object -ComObject Microsoft.Update.Session
$updateSearcher = $updateSession.CreateUpdateSearcher()

# Search for all updates
$allUpdates = $updateSearcher.Search("IsHidden=0")
# Search for updates that aren't installed
$notInstalledUpdates = $updateSearcher.Search("IsInstalled=0 and IsHidden=0").Updates

# Filter out downloaded and installed updates
$relevantUpdates = $allUpdates.Updates | Where-Object {($_.IsDownloaded -eq $false -or $_.IsInstalled -eq $false) -and $_.Title -notlike "Security Intelligence Update for Microsoft Defender Antivirus*"}
$relevantUpdates = $notInstalledUpdates | Where-Object { $_.Title -notlike "Security Intelligence Update for Microsoft Defender Antivirus*" }

# Get the count of available updates
$updateCount = $relevantUpdates.Count

# Get the count of important and critical updates
$criticalCount = $relevantUpdates | Where-Object {($_.MsrcSeverity -ge "Critical" -and $_.IsHidden -eq $false) -or $_.Title -like "Security Intelligence Update for Microsoft Defender Antivirus*"} | Measure-Object | Select-Object -ExpandProperty Count
$importantCount = $relevantUpdates | Where-Object {$_.MsrcSeverity -eq "Important" -and $_.IsHidden -eq $false -and $_.Title -notlike "Security Intelligence Update for Microsoft Defender Antivirus*"} | Measure-Object | Select-Object -ExpandProperty Count
$criticalCount = $relevantUpdates | Where-Object { ($_.MsrcSeverity -ge "Critical" -and $_.IsHidden -eq $false) -or $_.Title -like "Security Intelligence Update for Microsoft Defender Antivirus*" } | Measure-Object | Select-Object -ExpandProperty Count
$importantCount = $relevantUpdates | Where-Object { $_.MsrcSeverity -eq "Important" -and $_.IsHidden -eq $false -and $_.Title -notlike "Security Intelligence Update for Microsoft Defender Antivirus*" } | Measure-Object | Select-Object -ExpandProperty Count

# Set the exit code and message based on the number and severity of updates

Expand All @@ -43,4 +43,4 @@ if ($updateCount -eq 0) {
} else {
Write-Host "$updateCount Windows updates are available. $importantCount are important and $criticalCount are critical."
exit 2
}
}

0 comments on commit 32c6f6b

Please sign in to comment.