How to Retrieve Subnet and Route Table Information via PowerShell

Nana Poku 180 Reputation points
2025-02-05T23:25:21.94+00:00

What are the PowerShell commands to retrieve subnet and route table information from an Azure environment?

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,628 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Marcin Policht 35,210 Reputation points MVP
    2025-02-05T23:31:56.86+00:00

    1. Retrieve Subnet Information

    Get-AzVirtualNetwork | Select-Object -ExpandProperty Subnets
    

    Or, if you want details of a specific subnet:

    Get-AzVirtualNetworkSubnetConfig -Name <SubnetName> -VirtualNetwork <VNetObject>
    

    To get all subnets in a specific virtual network:

    $vnet = Get-AzVirtualNetwork -Name "<VNetName>" -ResourceGroupName "<ResourceGroupName>"
    $vnet.Subnets
    

    2. Retrieve Route Table Information To list all route tables in your Azure subscription:

    Get-AzRouteTable
    

    To get details of a specific route table:

    Get-AzRouteTable -Name "<RouteTableName>" -ResourceGroupName "<ResourceGroupName>"
    

    To list the routes within a specific route table:

    $routeTable = Get-AzRouteTable -Name "<RouteTableName>" -ResourceGroupName "<ResourceGroupName>"
    $routeTable.Routes
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

  2. Rohith Vinnakota 2,595 Reputation points Microsoft Vendor
    2025-02-11T00:57:52.65+00:00

    Hi @Nana Poku,

    Welcome to Microsoft Q&A Platform. Thank you for reaching out & hope you are doing well.

     

    
    # Get all virtual networks in the subscription
    $vNets = Get-AzVirtualNetwork
    
    
    # Loop through each VNet and retrieve its subnets along with route tables
    $results = foreach ($vNet in $vNets) {
        foreach ($subnet in $vNet.Subnets) {
            $routeTable = if ($subnet.RouteTable) { 
                Get-AzRouteTable -Name $subnet.RouteTable
            } else { 
                $null 
            }
     
            [PSCustomObject]@{
                VNetName     = $vNet.Name
                VNetRG       = $vNet.ResourceGroupName
                SubnetName   = $subnet.Name
                RouteTable   = if ($routeTable) { $routeTable.Name } else { "None" }
                RouteTableRG = if ($routeTable) { $routeTable.ResourceGroupName } else { "None" }
            }
        }
    }
    
    
    # Display results in a table format
    $results | Format-Table -AutoSize
    
    
    

    I hope this has been helpful!

    Your feedback is important so please take a moment to accept answers. If you still have questions, pleaslet us know what is needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.