[CmdletBinding()] param( [switch]$IncludeIPv6 ) $ErrorActionPreference = 'Stop' $families = @('IPv4') if ($IncludeIPv6) { $families += 'IPv6' } try { $rawRoutes = foreach ($family in $families) { Get-NetRoute -AddressFamily $family -ErrorAction Stop } } catch { throw "Не удалось прочитать маршруты: $($_.Exception.Message)" } $routes = foreach ($route in $rawRoutes) { $adapter = Get-NetAdapter -InterfaceIndex $route.ifIndex -ErrorAction SilentlyContinue $nextHop = $route.NextHop if ($nextHop -eq '0.0.0.0' -or $nextHop -eq '::') { $nextHop = 'direct' } [pscustomobject]@{ Destination = $route.DestinationPrefix NextHop = $nextHop Metric = $route.RouteMetric Interface = $(if ($adapter) { $adapter.Name } else { "if$($route.ifIndex)" }) State = $route.State } } $routes | Sort-Object Interface, Metric | Format-Table -AutoSize $defaults = @($routes | Where-Object { $_.Destination -eq '0.0.0.0/0' -or $_.Destination -eq '::/0' }) Write-Host "Маршрутов: $($routes.Count), по умолчанию: $($defaults.Count)" if ($defaults.Count -eq 0) { Write-Warning "Маршрут по умолчанию не найден" }