Script Sample - Generate Report for Route Tables with associated Subnets and related information@20aman Jan 06, 2019
When you have custom User Defined Routes (UDRs) in your environment on your Route Tables, you will have these Route Tables associated with various Subnets. If you want to report on the association of Route Tables with Subnets and any related information then you can use this sample script.
One use case is to use this script to export the associations so that if any association gets deleted then you can recreate later by reference to this report. Another script sample uses the output of this script to perform the association of the subnets to the Route Tables. That sample can be found here: Disassociate and Associate Subnets to Route Tables
Script Requirements and Workings
The script only requires you to update the path for the output csv report.
The script connects to the Azure and fetches all Route Tables by using the below command.
$routeTables = Get-AzureRmRouteTable
It then finds all the subnet linked on those Route Tables by using the Subnets property on the route table object as shown below.
$routeSubnets = $routeTable.Subnets
The script then iterates over all the subnets one by one. It then finds the related subnet information like Subscription id, the virtual network of the subnet and the Resource Group of the Virtual Network. It saves all this information to an array object named $results.
Finally, the script outputs all the results using the Export-Csv cmdlet:
$results | Export-Csv -Path $PathToOutputCSVReport -NoTypeInformation
Location of the Script
You can find this script in GitHub at this location: Report-UDRsWithSubnetInfo.ps1