[CmdletBinding()] param( [string]$OutputPath, [switch]$Json ) $ErrorActionPreference = 'Stop' $sound = @(Get-CimInstance -ClassName Win32_SoundDevice | Select-Object Name, Manufacturer, Status, DeviceID | Sort-Object Name) $pnp = @(Get-PnpDevice -Class AudioEndpoint, Media -ErrorAction SilentlyContinue | Select-Object Status, Class, FriendlyName, InstanceId, Problem | Sort-Object Status, Class, FriendlyName) $problem = @($pnp | Where-Object { $_.Status -ne 'OK' }) $result = [pscustomobject]@{ SoundDevices = $sound AudioEndpoints = $pnp ProblemCount = $problem.Count } Write-Host "Звуковых адаптеров: $($sound.Count), аудиоустройств: $($pnp.Count), проблемных: $($problem.Count)" if ($Json) { $text = $result | ConvertTo-Json -Depth 5 } else { $text = @() $text += 'Звуковые адаптеры:' $text += ($sound | Format-Table -AutoSize | Out-String -Width 220) $text += 'Аудиоустройства:' $text += ($pnp | Format-Table -AutoSize | Out-String -Width 240) $text = $text -join [Environment]::NewLine } if ($OutputPath) { $text | Set-Content -LiteralPath $OutputPath -Encoding UTF8 Write-Host "Отчёт сохранён: $OutputPath" } else { $text }