[CmdletBinding()] param( [ValidateRange(1, 200)] [int]$Max = 30, [switch]$AsJson ) $ErrorActionPreference = 'Stop' try { $session = New-Object -ComObject Microsoft.Update.Session $searcher = $session.CreateUpdateSearcher() $result = $searcher.Search("IsInstalled=0 and IsHidden=0") } catch { Write-Error "Не удалось получить список обновлений: $($_.Exception.Message)" exit 2 } $updates = @() foreach ($update in @($result.Updates | Select-Object -First $Max)) { $severity = '' if ($update.MsrcSeverity) { $severity = [string]$update.MsrcSeverity } $updates += [pscustomobject]@{ Title = [string]$update.Title Severity = $severity KB = (@($update.KBArticleIDs) -join ',') Downloaded = $update.IsDownloaded RebootRequired = $update.RebootRequired } } $hotfixes = @() try { $hotfixes = @(Get-HotFix -ErrorAction Stop | Sort-Object InstalledOn -Descending | Select-Object -First 5 HotFixID, Description, InstalledOn) } catch { $hotfixes = @() } $report = [pscustomobject]@{ PendingCount = $result.Updates.Count Updates = $updates RecentFixes = $hotfixes } if ($AsJson) { $report | ConvertTo-Json -Depth 5 exit 0 } Write-Host ("Ожидает обновлений: {0}" -f $result.Updates.Count) if ($updates.Count -eq 0) { Write-Host 'Список пуст.' } else { $updates | Format-Table Title, Severity, KB, Downloaded, RebootRequired -AutoSize } Write-Host '' Write-Host 'Последние установленные обновления:' if ($hotfixes.Count -eq 0) { Write-Host ' нет данных' } else { $hotfixes | Format-Table -AutoSize } exit 0