A script to present Azure Route Tables into a csv file
This file contains 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
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