Created
December 19, 2025 14:03
-
-
Save indifferentcats/caa428a76f22c1f185971eaaaa869a3a to your computer and use it in GitHub Desktop.
Find-DuplicateRoutes - PowerShell to identify with a split VPN has started duplicating routes to internal IP address but going around the VPN, resulting in stalled connections. (llama3:70b)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Find-DuplicateRoutes { | |
| # Get all network routes | |
| $routes = Get-NetRoute | |
| # Filter out default routes, link-local multicast routes, and link-local unicast routes | |
| $filteredRoutes = $routes | Where-Object { | |
| (-not ($_.DestinationPrefix -eq '0.0.0.0/0')) -and | |
| (-not ($_.DestinationPrefix -eq '::/0')) -and | |
| (-not ($_.DestinationPrefix -like 'ff00::/8*')) -and | |
| (-not ($_.DestinationPrefix -eq 'fe80::/64')) | |
| } | |
| # Group remaining routes by their DestinationPrefix | |
| $groupedRoutes = $filteredRoutes | Group-Object -Property DestinationPrefix | |
| # Identify groups where RouteMetric is not always unique | |
| $duplicateRoutes = @() | |
| foreach ($group in $groupedRoutes) { | |
| $routeMetrics = $group.Group | Select-Object -ExpandProperty RouteMetric | |
| if (($routeMetrics | Measure-Object -Maximum).Count -lt $group.Count) { | |
| $duplicateRoutes += [PSCustomObject]@{ | |
| DestinationPrefix = $group.Name | |
| DuplicateEntries = $group.Group | |
| } | |
| } | |
| } | |
| # Display the duplicate routes if found | |
| if ($null -ne $duplicateRoutes -and $duplicateRoutes.Count -gt 0) { | |
| Write-Host "The following duplicate routes were found (excluding default, link-local multicast, and link-local unicast routes):" | |
| foreach ($route in $duplicateRoutes) { | |
| Write-Host "Destination Prefix: $($route.DestinationPrefix)" | |
| $route.DuplicateEntries | Select-Object InterfaceAlias, DestinationPrefix, NextHop, RouteMetric, PolicyStore | Format-Table -AutoSize | |
| } | |
| } else { | |
| Write-Host "No duplicate routes found (excluding default, link-local multicast, and link-local unicast routes)." | |
| } | |
| } | |
| function Find-DuplicateRoutes { | |
| # Get all network routes | |
| $routes = Get-NetRoute | |
| # Filter out default routes, link-local multicast routes, and link-local unicast routes | |
| $filteredRoutes = $routes | Where-Object { | |
| (-not ($_.DestinationPrefix -eq '0.0.0.0/0')) -and | |
| (-not ($_.DestinationPrefix -eq '::/0')) -and | |
| (-not ($_.DestinationPrefix -like 'ff00::/8*')) -and | |
| (-not ($_.DestinationPrefix -eq 'fe80::/64')) | |
| } | |
| # Group remaining routes by their DestinationPrefix | |
| $groupedRoutes = $filteredRoutes | Group-Object -Property DestinationPrefix | |
| # Identify groups where RouteMetric is not always unique | |
| $duplicateRoutes = @() | |
| foreach ($group in $groupedRoutes) { | |
| $routeMetrics = $group.Group | Select-Object -ExpandProperty RouteMetric | |
| if (($routeMetrics | Measure-Object -Maximum).Count -lt $group.Count) { | |
| $duplicateRoutes += [PSCustomObject]@{ | |
| DestinationPrefix = $group.Name | |
| DuplicateEntries = $group.Group | |
| } | |
| } | |
| } | |
| # Display the duplicate routes if found | |
| if ($null -ne $duplicateRoutes -and $duplicateRoutes.Count -gt 0) { | |
| Write-Host "The following duplicate routes were found (excluding default, link-local multicast, and link-local unicast routes):" | |
| foreach ($route in $duplicateRoutes) { | |
| Write-Host "Destination Prefix: $($route.DestinationPrefix)" | |
| $route.DuplicateEntries | Select-Object InterfaceAlias, DestinationPrefix, NextHop, RouteMetric, PolicyStore | Format-Table -AutoSize | |
| } | |
| } else { | |
| Write-Host "No duplicate routes found (excluding default, link-local multicast, and link-local unicast routes)." | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment