Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script to present Azure Route Tables into a csv file
Connect-AzureRmAccount
$Subscription = "<Subscription-GUID>"
$LogFile = "C:\<PATH>\RouteTables.csv"
If (Test-Path $Logfile) {
Clear-Content -Path $Logfile
}
Add-Content $Logfile "Name,ResourceGroupName,Location,RouteName,Id,Etag,ProvisioningState,AddressPrefix,NextHopType,NextHopIpAddress"
Set-AzureRmContext -Subscription $Subscription
$RTs = Get-AzureRmRouteTable
ForEach ($RT in $RTs) {
# Nullify all values
$RTName = $NULL
$RTResourceGroupName = $NULL
$RTLocation = $NULL
$RTRouteName = $NULL
$RTId = $NULL
$RTEtag = $NULL
$RTProvisioningState = $NULL
$RTAddressPrefix = $NULL
$RTNextHopType = $NULL
$RTNextHopIpAddress = $NULL
# Get route values
$RTName = $RT.Name
$RTResourceGroupName = $RT.ResourceGroupName
$RTLocation = $RT.Location
$RTRoutes = $RT.Routes
ForEach ($RTRoute in $RTRoutes) {
$RTRouteName = $RTRoute.Name
$RTId = $RTRoute.Id
$RTEtag = $RTRoute.Etag
$RTProvisioningState = $RTRoute.ProvisioningState
$RTAddressPrefix = $RTRoute.AddressPrefix
$RTNextHopType = $RTRoute.NextHopType
$RTNextHopIpAddress = $RTRoute.NextHopIpAddress
# Define output
[String]$RTInfo = $RTName + "," + $RTResourceGroupName + "," + $RTLocation + "," + $RTRouteName + "," + $RTId + "," + $RTEtag + "," + $RTProvisioningState + "," + $RTAddressPrefix + "," + $RTNextHopType + "," + $RTNextHopIpAddress
Write-Host $RTInfo
# Write output to file
Add-Content $Logfile $RTInfo
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.