[CmdletBinding()] param( [switch]$IncludeStoppedManual, [string]$OutputPath, [switch]$Json ) $ErrorActionPreference = 'Stop' $services = Get-CimInstance -ClassName Win32_Service $rows = $services | Where-Object { ($_.StartMode -eq 'Auto' -and $_.State -ne 'Running') -or ($IncludeStoppedManual -and $_.StartMode -eq 'Manual' -and $_.State -eq 'Stopped') } | Select-Object Name, DisplayName, State, StartMode, StartName, ProcessId, @{ Name = 'Dependencies'; Expression = { ($_.Dependencies -join ', ') } }, @{ Name = 'DependentServices'; Expression = { ($_.DependentServices -join ', ') } } | Sort-Object Name Write-Host "Найдено проблемных служб: $($rows.Count)" if ($rows.Count -eq 0) { Write-Host 'Автоматические службы запущены, остановленных нет.' } if ($Json) { $text = $rows | ConvertTo-Json -Depth 4 } else { $text = $rows | Format-Table -Wrap | Out-String -Width 260 } if ($OutputPath) { $text | Set-Content -LiteralPath $OutputPath -Encoding UTF8 Write-Host "Отчёт сохранён: $OutputPath" } else { $text }