Skip to content

Instantly share code, notes, and snippets.

@contactbrenton
Last active April 14, 2024 07:58
Show Gist options
  • Save contactbrenton/2f071a73b03c51600bd832f6c85d49db to your computer and use it in GitHub Desktop.
Save contactbrenton/2f071a73b03c51600bd832f6c85d49db to your computer and use it in GitHub Desktop.
Check Windows updates using Windows Update Agent (WUA)
<#
.DESCRIPTION
The script uses a COM object to interact with the Windows Update service, searching for any updates that are currently available but not installed. If no updates are pending, it confirms the system is up to date. Otherwise, it lists all pending updates by title.
#>
# Create a COM object for Windows Update Session
$UpdateSession = New-Object -ComObject "Microsoft.Update.Session"
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
# Search for pending updates
$SearchResult = $UpdateSearcher.Search("IsInstalled=0")
# Check if there are updates available
if ($SearchResult.Updates.Count -eq 0) {
Write-Host "Your system is up to date."
} else {
Write-Host "There are updates pending. Details are as follows:"
foreach ($Update in $SearchResult.Updates) {
Write-Host "Update Title: $($Update.Title)"
}
}
# Inform the user about potential update restrictions
Write-Host "Note: Some updates, especially driver updates, may not be available due to management policies from RMM, Group Policy, Intune etc."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment