|
| 1 | +function Get-AbrAzRouteTable { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Used by As Built Report to retrieve Azure Route Table and Routes information |
| 5 | + .DESCRIPTION |
| 6 | +
|
| 7 | + .NOTES |
| 8 | + Version: 0.2 |
| 9 | + Author: Howard Hao & Tim Carman |
| 10 | + Twitter: tpcarman |
| 11 | + Github: howardhaooooo / tpcarman |
| 12 | + .EXAMPLE |
| 13 | +
|
| 14 | + .LINK |
| 15 | +
|
| 16 | + #> |
| 17 | + [CmdletBinding()] |
| 18 | + param ( |
| 19 | + ) |
| 20 | + |
| 21 | + begin { |
| 22 | + Write-PScriboMessage "RouteTable InfoLevel set at $($InfoLevel.RouteTable)." |
| 23 | + } |
| 24 | + |
| 25 | + process { |
| 26 | + $AzRouteTables = Get-AzRouteTable | Sort-Object Name |
| 27 | + if (($InfoLevel.RouteTable -gt 0) -and ($AzRouteTables)) { |
| 28 | + Write-PscriboMessage "Collecting Azure Route Table information." |
| 29 | + Section -Style Heading4 'Route Tables' { |
| 30 | + if ($Options.ShowSectionInfo) { |
| 31 | + Paragraph "Azure Route Tables are a set of custom routes that dictate how network traffic should move within a virtual network (VNet). They offer a way to control the flow of data, ensuring it reaches the correct endpoint. For instance, if a subnet in a VNet needs to communicate with a virtual appliance, an Azure Route Table can direct the traffic accordingly." |
| 32 | + BlankLine |
| 33 | + } |
| 34 | + $AzRouteTableInfo = @() |
| 35 | + foreach ($AzRouteTable in $AzRouteTables) { |
| 36 | + $InObj = [Ordered]@{ |
| 37 | + 'Name' = $AzRouteTable.Name |
| 38 | + 'Resource Group' = $AzRouteTable.ResourceGroupName |
| 39 | + 'Location' = $AzLocationLookup."$($AzRouteTable.Location)" |
| 40 | + 'Subscription' = "$($AzSubscriptionLookup.(($AzRouteTable.Id).split('/')[2]))" |
| 41 | + 'Provisioning State' = $AzRouteTable.ProvisioningState |
| 42 | + } |
| 43 | + $AzRouteTableInfo += [PSCustomObject]$InObj |
| 44 | + } |
| 45 | + |
| 46 | + if ($InfoLevel.RouteTable -eq 1) { |
| 47 | + Paragraph "The following table summarises the configuration of the Route Table within the $($AzSubscription.Name) subscription." |
| 48 | + BlankLine |
| 49 | + } else { |
| 50 | + Paragraph "The following sections detail the configuration of the Route Tables within the $($AzSubscription.Name) subscription." |
| 51 | + BlankLine |
| 52 | + } |
| 53 | + $TableParams = @{ |
| 54 | + Name = "Route Tables - $($AzSubscription.Name)" |
| 55 | + List = $false |
| 56 | + Columns = 'Name', 'Resource Group', 'Location', 'Subscription' |
| 57 | + ColumnWidths = 25, 25, 25, 25 |
| 58 | + } |
| 59 | + if ($Report.ShowTableCaptions) { |
| 60 | + $TableParams['Caption'] = "- $($TableParams.Name)" |
| 61 | + } |
| 62 | + $AzRouteTableInfo | Table @TableParams |
| 63 | + |
| 64 | + if ($InfoLevel.RouteTable -ge 2) { |
| 65 | + foreach ($AzRouteTable in $AzRouteTables) { |
| 66 | + $AzRoutes = $AzRouteTable.Routes | Sort-Object Name |
| 67 | + if ($AzRoutes) { |
| 68 | + Section -Style NOTOCHeading5 -ExcludeFromTOC "$($AzRouteTable.Name)" { |
| 69 | + Section -Style NOTOCHeading6 -ExcludeFromTOC "Routes" { |
| 70 | + $AzRouteInfo = @() |
| 71 | + foreach ($AzRoute in $AzRoutes){ |
| 72 | + $InObj = [Ordered]@{ |
| 73 | + 'Name' = $AzRoute.Name |
| 74 | + 'Address Prefix' = $AzRoute.AddressPrefix |
| 75 | + 'Next Hop Type' = $AzRoute.NextHopType |
| 76 | + 'Next Hop IP Address' = Switch ($AzRoute.NextHopIpAddress) { |
| 77 | + "" { '--' } |
| 78 | + default { $AzRoute.NextHopIpAddress } |
| 79 | + } |
| 80 | + } |
| 81 | + $AzRouteInfo += [PSCustomObject]$InObj |
| 82 | + } |
| 83 | + $TableParams = @{ |
| 84 | + Name = "Routes - $($AzRouteTable.Name)" |
| 85 | + List = $false |
| 86 | + ColumnWidths = 25, 25, 25, 25 |
| 87 | + } |
| 88 | + if ($Report.ShowTableCaptions) { |
| 89 | + $TableParams['Caption'] = "- $($TableParams.Name)" |
| 90 | + } |
| 91 | + $AzRouteInfo | Table @TableParams |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + end {} |
| 102 | +} |
0 commit comments