Azure route tables: export routes by destination prefix
Overview
This PowerShell script searches every enabled Azure subscription available to the current account, inspects every route table, and exports only the routes whose destination prefix starts with a specific value.
In its current form, the filter is:
10.114.*This is useful when you need to quickly answer questions such as:
- Which route tables contain routes for a given private range?
- Which subscription and resource group owns those routes?
- What next hop is configured for each matching prefix?
What the script does
- Retrieves enabled Azure subscriptions with
Get-AzSubscription. - Switches context into each subscription with
Set-AzContext. - Reads route tables with
Get-AzRouteTable. - Filters routes where
AddressPrefixmatches10.114.*. - Prints matches immediately to the console.
- Collects all matches into objects for sorting and CSV export.
- Writes a CSV file to the user home directory.
Prerequisites
Install the Azure PowerShell modules if needed:
Install-Module Az -Scope CurrentUserConnect to Azure before running the script:
Connect-AzAccountThe account must have permission to read route tables in the subscriptions being checked.
Output
The CSV is written to:
$HOME/routes-10.114.csvEach row includes:
SubscriptionNameSubscriptionIdResourceGroupRouteTableLocationRouteNameAddressPrefixNextHopTypeNextHopIpAddress
PowerShell script
$CsvPath = "$HOME/routes-10.114.csv"
$results = [System.Collections.Generic.List[object]]::new()
$subscriptions = Get-AzSubscription |
Where-Object { $_.State -eq "Enabled" }
foreach ($sub in $subscriptions) {
Write-Host ""
Write-Host "Checking subscription: $($sub.Name) [$($sub.Id)]" -ForegroundColor Cyan
try {
Set-AzContext -SubscriptionId $sub.Id -ErrorAction Stop | Out-Null
$routeTables = Get-AzRouteTable -ErrorAction Stop
foreach ($routeTable in $routeTables) {
foreach ($route in $routeTable.Routes) {
if ($route.AddressPrefix -like "10.114.*") {
$result = [PSCustomObject]@{
SubscriptionName = $sub.Name
SubscriptionId = $sub.Id
ResourceGroup = $routeTable.ResourceGroupName
RouteTable = $routeTable.Name
Location = $routeTable.Location
RouteName = $route.Name
AddressPrefix = $route.AddressPrefix
NextHopType = $route.NextHopType
NextHopIpAddress = $route.NextHopIpAddress
}
$results.Add($result)
Write-Host "MATCH: " -ForegroundColor Green -NoNewline
Write-Host "$($route.AddressPrefix) " -ForegroundColor Yellow -NoNewline
Write-Host "-> $($route.NextHopType)"
Write-Host " Route Table: $($routeTable.Name)"
Write-Host " Resource Group: $($routeTable.ResourceGroupName)"
Write-Host " Route: $($route.Name)"
if ($route.NextHopIpAddress) {
Write-Host " Next Hop IP: $($route.NextHopIpAddress)"
}
Write-Host ""
}
}
}
}
catch {
Write-Warning "Failed to process subscription '$($sub.Name)': $($_.Exception.Message)"
}
}
$sortedResults = $results |
Sort-Object SubscriptionName, ResourceGroup, RouteTable, AddressPrefix
$sortedResults |
Export-Csv -Path $CsvPath -NoTypeInformation
Write-Host ""
Write-Host "===================== RESULTS =====================" -ForegroundColor Cyan
if ($results.Count -gt 0) {
$sortedResults |
Format-Table `
SubscriptionName,
ResourceGroup,
RouteTable,
RouteName,
AddressPrefix,
NextHopType,
NextHopIpAddress `
-AutoSize
Write-Host ""
Write-Host "Found $($results.Count) matching routes." -ForegroundColor Green
Write-Host "CSV exported to: $CsvPath" -ForegroundColor Green
}
else {
Write-Host "No routes starting with 10.114. were found." -ForegroundColor Yellow
}Notes
- The current filter uses
-like "10.114.*", so it matches string prefixes rather than CIDR math. - If you want a reusable variant, move
10.114and$CsvPathinto parameters. - If some subscriptions fail, the script continues and prints a warning instead of stopping the full scan.