Skip to content

Instantly share code, notes, and snippets.

@mortenya
Last active August 29, 2015 14:12
Show Gist options
  • Save mortenya/62c95b3ec975d4331db2 to your computer and use it in GitHub Desktop.
Save mortenya/62c95b3ec975d4331db2 to your computer and use it in GitHub Desktop.
Function to grab Definition updates for Windows Defender. Felt a little messy how I used the foreach loop, but it works.
Function WSUSUpdate {
<#
Slight modification of https://gist.github.com/jacobludriks/9ca9ce61de251a5476f1
#>
$Criteria = "IsInstalled=0 and Type='Software'"
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
try {
$SearchResult = $Searcher.Search($Criteria).Updates
if ($SearchResult.Count -eq 0) {
Write-Output "There are no applicable updates."
exit
} else {
$Session = New-Object -ComObject Microsoft.Update.Session
$Downloader = $Session.CreateUpdateDownloader()
$Installer = New-Object -ComObject Microsoft.Update.Installer
foreach ($i in 0..$SearchResult.Count) {
try {
if (($SearchResult.Item($i).Title) -like 'Definition Update for Windows Defender - KB*') {
$Downloader.Updates = $SearchResult[$i]
$Downloader.Download()
$Installer.Updates = $SearchResult[$i]
$Result = $Installer.Install()
#$SearchResult[$i]
}
}
catch { }
}
}
}
catch {
Write-Output "There are no applicable updates."
}
}
WSUSUpdate
#If ($Result.rebootRequired) { Restart-Computer }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment