PowerShell Genie

Get-NetRoute

Use Get-NetRoute to list the machine's IP routing table entries with their destinations and metrics.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — PowerShell module reference

Syntax

1PS> Get-NetRoute [[-DestinationPrefix] <string[]>] [-InterfaceIndex <UInt32[]>] [-InterfaceAlias <String[]>] [-AddressFamily <AddressFamily[]>] [-NextHop <String[]>] [-CimSession <CimSession[]>] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Get-NetRoute [[-DestinationPrefix] <string[]>] [-InterfaceIndex <UInt32[]>] [-InterfaceAlias <String[]>] [-AddressFamily <AddressFamily[]>] [-NextHop <String[]>] [-CimSession <CimSession[]>] [<CommonParameters>]
  1. Stage 1Get-NetRoute-DestinationPrefix -InterfaceIndex -InterfaceAlias -AddressFamily -NextHop -CimSession

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Get-NetRoute -DestinationPrefix 0.0.0.0/0

    1PS> Get-NetRoute -DestinationPrefix 0.0.0.0/0 | Select-Object InterfaceAlias, NextHop, RouteMetric
    Show reference output

    Sample output · fictional data, shaped like the real thing

    InterfaceAlias  NextHop     RouteMetric
    --------------  ----------  -----------
                    10.20.30.1  25
                    0.0.0.0     256

    Sort by RouteMetric

    1PS> Get-NetRoute -AddressFamily IPv4 | Sort-Object RouteMetric | Select-Object -First 5 DestinationPrefix, NextHop, RouteMetric
    Show reference output

    Sample output · fictional data, shaped like the real thing

    DestinationPrefix  NextHop     RouteMetric
    -----------------  ----------  -----------
    0.0.0.0/0          10.20.30.1  25
    10.20.30.0/24      0.0.0.0     256

    Get-NetRoute -InterfaceIndex 12

    1PS> Get-NetRoute -InterfaceIndex 12 | Measure-Object
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Count    : 2
    Average  :
    Sum      :
    Maximum  :
    Minimum  :
    Property :

    Parameters

    Parameter definitions:

    • -DestinationPrefix
    • -InterfaceIndex
    • -InterfaceAlias
    • -AddressFamily
    • -NextHop
    • -CimSession

    PowerShell module reference on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Get-NetRoute when you need to list the machine's IP routing table entries with their destinations and metrics. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: An unexpected route may belong to another interface or policy store. Inspect DestinationPrefix, NextHop and InterfaceIndex before interpreting it as the path for your target. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Test-NetConnection. Get-NetRoute reads routing entries; Test-NetConnection performs supported reachability checks. A stored route is configuration, not proof that the destination accepted a connection. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Get-NetRoute reference on Microsoft Learn

    Recap

    Get-NetRoute Use Get-NetRoute to list the machine's IP routing table entries with their destinations and metrics.

    Next: Get-LocalUser
    Genie guideGet-NetRoute

    Use Get-NetRoute to list the machine's IP routing table entries with their destinations and metrics. The console below is pre-loaded — run it, then change a value and run it again.