$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$SearchResult = $Searcher.Search("IsInstalled=0")
$DefenderUpdates = $SearchResult.Updates | Where-Object { $_.Title -like "*Windows Defender*" }
$DefenderUpdates | Select-Object -Property Title, UpdateID
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = New-Object -ComObject Microsoft.Update.UpdateColl
foreach ($Update in $DefenderUpdates) {
$Downloader.Updates.Add($Update)
}
$Downloader.Download()
$Installer = $Session.CreateUpdateInstaller()
$Installer.Updates = $Downloader.Updates
$InstallationResult = $Installer.Install()
# Вывод результатов установки
foreach ($Update in $Installer.Updates) {
Write-Output "Title: $($Update.Title)"
Write-Output "Result: $($InstallationResult.GetUpdateResult($Installer.Updates.IndexOf($Update)).ResultCode)"
}