[CmdletBinding()] param( [string]$Json ) $ErrorActionPreference = 'Stop' if (-not (Get-Command Get-MpComputerStatus -ErrorAction SilentlyContinue)) { throw 'Командлеты Microsoft Defender недоступны на этой системе.' } try { $status = Get-MpComputerStatus -ErrorAction Stop $prefs = Get-MpPreference -ErrorAction Stop } catch { throw "Не удалось прочитать статус Defender. Попробуйте запуск от имени администратора: $_" } $rows = @( [pscustomobject]@{ Setting = 'AntivirusEnabled'; Value = $status.AntivirusEnabled } [pscustomobject]@{ Setting = 'RealTimeProtectionEnabled'; Value = $status.RealTimeProtectionEnabled } [pscustomobject]@{ Setting = 'BehaviorMonitorEnabled'; Value = $status.BehaviorMonitorEnabled } [pscustomobject]@{ Setting = 'AntispywareEnabled'; Value = $status.AntispywareEnabled } [pscustomobject]@{ Setting = 'NISEnabled'; Value = $status.NISEnabled } [pscustomobject]@{ Setting = 'AntivirusSignatureVersion'; Value = $status.AntivirusSignatureVersion } [pscustomobject]@{ Setting = 'AntivirusSignatureLastUpdated'; Value = $status.AntivirusSignatureLastUpdated } [pscustomobject]@{ Setting = 'QuickScanStartTime'; Value = $status.QuickScanStartTime } [pscustomobject]@{ Setting = 'FullScanStartTime'; Value = $status.FullScanStartTime } ) $rows | Format-Table -AutoSize $prefRow = [pscustomobject]@{ DisableRealtimeMonitoring = $prefs.DisableRealtimeMonitoring DisableBehaviorMonitoring = $prefs.DisableBehaviorMonitoring DisableIOAVProtection = $prefs.DisableIOAVProtection DisableScriptScanning = $prefs.DisableScriptScanning MAPSReporting = $prefs.MAPSReporting SubmitSamplesConsent = $prefs.SubmitSamplesConsent SignatureUpdateInterval = $prefs.SignatureUpdateInterval ExclusionPath = ($prefs.ExclusionPath -join '; ') ExclusionExtension = ($prefs.ExclusionExtension -join '; ') ExclusionProcess = ($prefs.ExclusionProcess -join '; ') } Write-Host 'Основные параметры:' $prefRow | Format-List if ($Json) { $parent = Split-Path -Parent $Json if ($parent -and -not (Test-Path -LiteralPath $parent)) { New-Item -ItemType Directory -Path $parent | Out-Null } $report = [pscustomobject]@{ Status = $status; Preferences = $prefRow } $report | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath $Json -Encoding UTF8 Write-Host "Снимок сохранён: $Json" } Write-Host 'Проверка не запускалась, настройки не изменялись.'