[CmdletBinding()] param( [switch]$AsJson, [ValidateRange(1, 200)] [int]$MaxRules = 20 ) $ErrorActionPreference = 'Stop' if (-not (Get-Command Get-NetFirewallProfile -ErrorAction SilentlyContinue)) { Write-Error 'Модуль NetSecurity недоступен.' exit 2 } try { $profiles = @(Get-NetFirewallProfile -ErrorAction Stop) $rules = @(Get-NetFirewallRule -Enabled True -ErrorAction SilentlyContinue) } catch { Write-Error "Не удалось прочитать правила firewall: $($_.Exception.Message)" exit 2 } $profileInfo = @($profiles | Select-Object Name, Enabled, DefaultInboundAction, DefaultOutboundAction, LogAllowed, LogBlocked) $inbound = @($rules | Where-Object { $_.Direction -eq 'Inbound' }) $byAction = @($inbound | Group-Object Action | Select-Object Name, Count) $publicAllow = @($inbound | Where-Object { $_.Action -eq 'Allow' -and ([string]$_.Profile) -match 'Public' } | Select-Object -First $MaxRules DisplayName, Profile, Action) $result = [pscustomobject]@{ Profiles = $profileInfo InboundByAction = $byAction PublicAllow = $publicAllow } if ($AsJson) { $result | ConvertTo-Json -Depth 5 exit 0 } $profileInfo | Format-Table -AutoSize Write-Host 'Входящие правила по действиям:' $byAction | Format-Table -AutoSize Write-Host "Разрешающие правила Public (первые $MaxRules):" if ($publicAllow.Count -eq 0) { Write-Host ' не найдены' } else { $publicAllow | Format-Table -AutoSize } $disabled = @($profiles | Where-Object { -not $_.Enabled }) if ($disabled.Count -gt 0) { Write-Warning ("Выключены профили: " + (($disabled | ForEach-Object { $_.Name }) -join ', ')) exit 1 } Write-Host 'Все профили firewall включены.' exit 0