Export Azure Routes to CSV via PowerShell

I needed a way of exporting all route tables within an Azure sub to a CSV in a format that could be used to recreate them if required. The following PS does the trick.

$rts=Get-AzureRmroutetable$rts=Get-AzureRmroutetable$outputfinal=@()foreach ($rt in $rts) { $routes=$rt.routes foreach ($route in $routes) { $Outputtemp = “” | SELECT VNETname,SubnetName,RTName,RGName,Location,RouteName,AddressPrefix,NextHopType,NextHopIPAddress
$separator = “/” $SubnetIDSplit=$rt.subnets.id.Split($separator)
$outputtemp.SubnetName=$SubnetIDSplit[-1] $outputtemp.VNETName=$SubnetIDSplit[-3] $outputtemp.RTName=$rt.name $outputtemp.RGName=$rt.Resourcegroupname $outputtemp.location=$rt.location $outputtemp.routename=$route.Name $outputtemp.AddressPrefix=$route.AddressPrefix $outputtemp.nexthoptype=$route.nexthoptype $outputtemp.NextHopIPAddress=$route.NextHopIPAddress $outputfinal += $outputtemp } }$outputfinal |export-csv .\route.csv -NoTypeInformation

Advertisements