Skip to content

Instantly share code, notes, and snippets.

@smitmartijn
Created June 14, 2018 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smitmartijn/f8b45c5dc6288ff53f77d19e72a23a7c to your computer and use it in GitHub Desktop.
Save smitmartijn/f8b45c5dc6288ff53f77d19e72a23a7c to your computer and use it in GitHub Desktop.
Get all routes on all NSX Edges via PowerNSX
# This snippet gets all the IP routes
#
# Import-Module PowerNSX and run
# Connect-NsxServer before running this.
$edges = Get-NsxEdge
foreach($edge in $edges)
{
Write-Host "Getting routes for Edge $($edge.name) ($($edge.id))"
# Use Invoke-NsxCli to execute a "show edge edge-id ip route" via the NSX Central CLI to get the routes
$raw_show_ip_route = (Invoke-NsxCli -SupressWarning -Query "show edge $($edge.id) ip route" -RawOutput).Split([Environment]::NewLine)
# No response? Go on to the next edge
if($raw_show_ip_route -eq $null) {
continue
}
# i.e. S 0.0.0.0/0 [1/0] via 10.8.25.1
# Filter on 'via'
$raw_routes = $raw_show_ip_route | where {$_.Contains("via")}
# No routes? Go on to the next edge
if($raw_routes -eq $null) {
continue
}
# Filter on / (route subnet) and not [ (metric)
$routes = $raw_routes.Split(" ") | where {$_.Contains("/")} | where {!($_.Contains("["))}
# What remains is a list of route subnets
Write-Host "Routes:"
# Output
$routes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment