[CmdletBinding()] param( [string]$Output ) $ErrorActionPreference = 'Stop' $lines = New-Object System.Collections.Generic.List[string] function Add-Line { param([string]$Text) $lines.Add($Text) } function Add-Section { param( [string]$Title, [scriptblock]$Body ) Add-Line "## $Title" Add-Line '' try { $items = @(& $Body) if ($items.Count -eq 0) { Add-Line '- нет данных' } else { foreach ($item in $items) { Add-Line "- $item" } } } catch { Add-Line "- ошибка: $($_.Exception.Message)" } Add-Line '' } Add-Line '# Отчёт по безопасности Windows' Add-Line '' Add-Line ("Дата: {0}" -f (Get-Date -Format 'yyyy-MM-dd HH:mm')) Add-Line ("Компьютер: {0}" -f $env:COMPUTERNAME) Add-Line '' Add-Section 'Система' { $os = Get-CimInstance Win32_OperatingSystem "ОС: $($os.Caption) $($os.Version)" "Последняя загрузка: $($os.LastBootUpTime)" } Add-Section 'Defender' { $status = Get-MpComputerStatus "AntivirusEnabled: $($status.AntivirusEnabled)" "RealTimeProtectionEnabled: $($status.RealTimeProtectionEnabled)" "SignatureAge: $($status.AntivirusSignatureAge)" "AMServiceEnabled: $($status.AMServiceEnabled)" } Add-Section 'Firewall' { Get-NetFirewallProfile | ForEach-Object { "$($_.Name): Enabled=$($_.Enabled), Inbound=$($_.DefaultInboundAction), Outbound=$($_.DefaultOutboundAction)" } } Add-Section 'BitLocker' { Get-BitLockerVolume | ForEach-Object { "$($_.MountPoint): $($_.VolumeStatus), защита=$($_.ProtectionStatus), $($_.EncryptionPercentage)%" } } Add-Section 'Администраторы' { $members = @() try { $group = Get-LocalGroup -SID 'S-1-5-32-544' -ErrorAction Stop $members = @(Get-LocalGroupMember -Group $group -ErrorAction Stop) } catch { $members = @(Get-LocalGroupMember -Group 'Administrators' -ErrorAction Stop) } $members | ForEach-Object { "$($_.Name) [$($_.ObjectClass)]" } } Add-Section 'Обновления' { $session = New-Object -ComObject Microsoft.Update.Session $searcher = $session.CreateUpdateSearcher() $result = $searcher.Search("IsInstalled=0 and IsHidden=0") "Ожидает обновлений: $($result.Updates.Count)" Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 5 | ForEach-Object { "$($_.HotFixID) $($_.InstalledOn)" } } Add-Section 'SMB1' { $feature = Get-WindowsOptionalFeature -Online -FeatureName SMB1Protocol -ErrorAction Stop "Состояние: $($feature.State)" } Add-Section 'Неудачные входы за сутки' { $start = (Get-Date).AddDays(-1) $events = @(Get-WinEvent -FilterHashtable @{LogName = 'Security'; Id = 4625; StartTime = $start} -ErrorAction Stop) "Событий 4625: $($events.Count)" } $text = ($lines -join "`r`n") + "`r`n" Write-Output $text if ($Output) { $text | Set-Content -LiteralPath $Output -Encoding UTF8 Write-Host "Отчёт сохранён: $Output" } exit 0