[CmdletBinding()] param( [switch]$IncludeHidden, [string]$OutputPath, [switch]$Json ) $ErrorActionPreference = 'Stop' $adapters = Get-NetAdapter -IncludeHidden:$IncludeHidden $rows = foreach ($adapter in $adapters) { $stats = $null try { $stats = Get-NetAdapterStatistics -Name $adapter.Name -ErrorAction Stop } catch { $stats = $null } $received = $null $sent = $null $receiveErrors = $null $sendErrors = $null $receiveDiscarded = $null $sendDiscarded = $null if ($stats) { $received = $stats.ReceivedBytes $sent = $stats.OutboundBytes $receiveErrors = $stats.ReceivedPacketErrors $sendErrors = $stats.OutboundPacketErrors $receiveDiscarded = $stats.ReceivedDiscardedPackets $sendDiscarded = $stats.OutboundDiscardedPackets } [pscustomobject]@{ Name = $adapter.Name Status = $adapter.Status LinkSpeed = $adapter.LinkSpeed MacAddress = $adapter.MacAddress ReceivedBytes = $received SentBytes = $sent ReceiveErrors = $receiveErrors SendErrors = $sendErrors ReceiveDiscarded = $receiveDiscarded SendDiscarded = $sendDiscarded } } $rows = $rows | Sort-Object Name $problem = @($rows | Where-Object { $_.Status -ne 'Up' -or $_.ReceiveErrors -gt 0 -or $_.SendErrors -gt 0 -or $_.ReceiveDiscarded -gt 0 -or $_.SendDiscarded -gt 0 }) Write-Host "Адаптеров: $(@($rows).Count), с замечаниями: $($problem.Count)" if ($Json) { $text = $rows | ConvertTo-Json -Depth 4 } else { $text = $rows | Format-Table -AutoSize | Out-String -Width 260 } if ($OutputPath) { $text | Set-Content -LiteralPath $OutputPath -Encoding UTF8 Write-Host "Отчёт сохранён: $OutputPath" } else { $text }