locked
Get-Netroute and 'route print' giving different route metric RRS feed

  • Question

  • I was reading Get-Netroute is the powershell equivalent of 'route print'.

    However, the output of both the commands gives me different values for route metric. The below is from a test computer. Yes, I know it has two NIC , each with a default gateway set. (I know it is not a good idea. But that is a separate topic)

    (1) Route print has (I have truncated the output)

    Network Destination        Netmask          Gateway       Interface  Metric
              0.0.0.0          0.0.0.0       10.100.1.1     10.100.1.100    271
              0.0.0.0          0.0.0.0      10.150.17.1     10.150.17.64     16

    (2) Get-netroute has (I have truncated the output as well)

    PS C:\> get-netroute

    ifIndex DestinationPrefix                              NextHop                                  RouteMetric PolicyStore
    ------- -----------------                              -------                                  ----------- -----------

    7       0.0.0.0/0                                      10.150.17.1                                        1 ActiveStore
    6       0.0.0.0/0                                      10.100.1.1                                       256 ActiveStore


    --------------------------------------------

    I trust the 'route print' only because I have been using it for 20 years :-). Anyhow what is the difference here? How do I get the real one?


    Friday, July 17, 2020 6:19 AM

Answers

  • Yes, something's not right there. The Get-NetRoute uses a CIM-instance (from WMI) and then "prettifies" it. In the CIM class the InterfaceMetric is named "Metric1". You can get that information yourself and see if it's present. You have a problem, but where that is isn't clear.

          gwmi win32_IP4RouteTable

    The description of the object returned is here:
    https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wmiiprouteprov/win32-ip4routetable

    The primary route metric is found in the property "Metric2". The remaining metric properties are for alternate routes.

    If you have an interface metric in the CIM data but not in the PowerShell output the problem may be in PowerShell or .Net. If it's not present in the CIM data you may have a problem with the WMI repository.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by Sydney IT guy Sunday, July 19, 2020 11:57 PM
    Sunday, July 19, 2020 2:58 PM

All replies

  • I'm pretty sure that "route print" is showing you the sum of the interface metric and the route metric. The Get-NetRoute shows the two metrics individually.

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Friday, July 17, 2020 7:59 PM
  • Thanks Rich. I guessed the 'route print' gives the 'effective' metric. Because, I could see real traffic flowing through the route with the lowest metric shown in 'route print'.

    However, Get-Netroute gives just one metric. Not two.

    It is  titled 'RouteMetric". But it does look like the 'effective route'.

    Sorry, my question still is , "what is the powershell equivalent' of 'route print' ? "

    Saturday, July 18, 2020 9:01 AM
  • How about trying a bit of tricky math?

    get-netroute|select @{n='Metric';e={$_.routemetric+$_.interfacemetric }}


    \_(ツ)_/

    Saturday, July 18, 2020 4:25 PM
  • I'm not sure (from your previously posted example) whether you've removed one of the columns from the Get-Netroute output. Here's an example of what I see (edited for brevity):

       ifIndex DestinationPrefix      NextHop   RouteMetric  ifMetric   PolicyStore
       ------- -----------------         -------       -----------        --------     -----------
       19      255.255.255.255/32  0.0.0.0      256                25           ActiveStore
       1        255.255.255.255/32  0.0.0.0      256                75           ActiveStore
       11      192.168.1.0/24         0.0.0.0      256                55           Active

    Try this (adjusting the parameters to suit your needs) and see if it looks better:

    get-netroute -state alive -AddressFamily ipv4 | 
        select ifIndex,DestinationPrefix,NextHop,@{n='Metric';e={($_.RouteMetric + $_.InterFaceMetric)}}|
            ft


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Saturday, July 18, 2020 5:37 PM
  • Mine is Windows Server 2016. Both gives the same numbers

    (1)

    PS C:\> get-netroute|select @{n='Metric';e={$_.routemetric+$_.interfacemetric }}

    Metric
    ------
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256
       256

    (2)

    PS C:\> get-netroute

    ifIndex DestinationPrefix                              NextHop                                  RouteMetric PolicyStore
    ------- -----------------                              -------                                  ----------- -----------
    6       255.255.255.255/32                             0.0.0.0                                          256 ActiveStore
    7       255.255.255.255/32                             0.0.0.0                                          256 ActiveStore
    1       255.255.255.255/32                             0.0.0.0                                          256 ActiveStore
    6       224.0.0.0/4                                    0.0.0.0                                          256 ActiveStore
    7       224.0.0.0/4                                    0.0.0.0                                          256 ActiveStore
    1       224.0.0.0/4                                    0.0.0.0                                          256 ActiveStore
    1       127.255.255.255/32                             0.0.0.0                                          256 ActiveStore
    1       127.0.0.1/32                                   0.0.0.0                                          256 ActiveStore
    1       127.0.0.0/8                                    0.0.0.0                                          256 ActiveStore
    7       10.150.17.255/32                               0.0.0.0                                          256 ActiveStore
    7       10.150.17.64/32                                0.0.0.0                                          256 ActiveStore
    7       10.150.17.0/24                                 0.0.0.0                                          256 ActiveStore
    6       10.100.127.255/32                              0.0.0.0                                          256 ActiveStore
    6       10.100.1.100/32                                0.0.0.0                                          256 ActiveStore
    6       10.100.0.0/17                                  0.0.0.0                                          256 ActiveStore
    7       0.0.0.0/0                                      10.150.17.1                                      256 ActiveStore
    6       0.0.0.0/0                                      10.100.1.1                                       256 ActiveStore
    1       ff00::/8                                       ::                                               256 ActiveStore
    4       fe80::5efe:10.150.17.64/128                    ::                                               256 ActiveStore
    3       fe80::5efe:10.100.1.100/128                    ::                                               256 ActiveStore
    1       ::1/128                                        ::                                               256 ActiveStore

    But

    (3)

    PS C:\> route print
    ===========================================================================
    Interface List
      7...00 15 5d f6 ca 02 ......Microsoft Hyper-V Network Adapter
      6...00 15 5d f6 ca 03 ......Microsoft Hyper-V Network Adapter #2
      1...........................Software Loopback Interface 1
      4...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
      3...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
    ===========================================================================

    IPv4 Route Table
    ===========================================================================
    Active Routes:
    Network Destination        Netmask          Gateway       Interface  Metric
              0.0.0.0          0.0.0.0       10.100.1.1     10.100.1.100    271
              0.0.0.0          0.0.0.0      10.150.17.1     10.150.17.64    271
           10.100.0.0    255.255.128.0         On-link      10.100.1.100    271
         10.100.1.100  255.255.255.255         On-link      10.100.1.100    271
       10.100.127.255  255.255.255.255         On-link      10.100.1.100    271
          10.150.17.0    255.255.255.0         On-link      10.150.17.64    271
         10.150.17.64  255.255.255.255         On-link      10.150.17.64    271
        10.150.17.255  255.255.255.255         On-link      10.150.17.64    271
            127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
            127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
      127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
            224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
            224.0.0.0        240.0.0.0         On-link      10.150.17.64    271
            224.0.0.0        240.0.0.0         On-link      10.100.1.100    271
      255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
      255.255.255.255  255.255.255.255         On-link      10.150.17.64    271
      255.255.255.255  255.255.255.255         On-link      10.100.1.100    271
    ===========================================================================
    Persistent Routes:
      Network Address          Netmask  Gateway Address  Metric
              0.0.0.0          0.0.0.0       10.100.1.1  Default
              0.0.0.0          0.0.0.0      10.150.17.1  Default
    ===========================================================================

    IPv6 Route Table
    ===========================================================================
    Active Routes:
     If Metric Network Destination      Gateway
      1    331 ::1/128                  On-link
      1    331 ff00::/8                 On-link
    ===========================================================================
    Persistent Routes:

    Sunday, July 19, 2020 7:10 AM
  • Thank Rich. No I did not remove any column. The OS is Windows server 2016

    get-netroute | fl

    Sample output for one entry

    DestinationPrefix : 0.0.0.0/0
    InterfaceIndex    : 7
    InterfaceAlias    : Ethernet
    CompartmentId     : 1
    AddressFamily     : IPv4
    NextHop           : 10.150.17.1
    Publish           : No
    RouteMetric       : 256
    Protocol          : NetMgmt
    ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
    PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
    PolicyStore       : ActiveStore

    Sunday, July 19, 2020 7:13 AM
  • It appears that you may be missing a Net update.

    What version of PowerShell?


    \_(ツ)_/

    Sunday, July 19, 2020 7:21 AM
  • Yes, something's not right there. The Get-NetRoute uses a CIM-instance (from WMI) and then "prettifies" it. In the CIM class the InterfaceMetric is named "Metric1". You can get that information yourself and see if it's present. You have a problem, but where that is isn't clear.

          gwmi win32_IP4RouteTable

    The description of the object returned is here:
    https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wmiiprouteprov/win32-ip4routetable

    The primary route metric is found in the property "Metric2". The remaining metric properties are for alternate routes.

    If you have an interface metric in the CIM data but not in the PowerShell output the problem may be in PowerShell or .Net. If it's not present in the CIM data you may have a problem with the WMI repository.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by Sydney IT guy Sunday, July 19, 2020 11:57 PM
    Sunday, July 19, 2020 2:58 PM
  • It appears that you may be missing a Net update.

    What version of PowerShell?


    \_(ツ)_/

    PSVersion                      5.1.14393.2097
    Sunday, July 19, 2020 11:51 PM
  • Check to be sure all versions of Net are correct and that all updates and upgrades to the OS and Net have been applied.


    \_(ツ)_/


    • Edited by jrv Sunday, July 19, 2020 11:55 PM
    Sunday, July 19, 2020 11:55 PM
  • Yes, something's not right there. The Get-NetRoute uses a CIM-instance (from WMI) and then "prettifies" it. In the CIM class the InterfaceMetric is named "Metric1". You can get that information yourself and see if it's present. You have a problem, but where that is isn't clear.

          gwmi win32_IP4RouteTable

    The description of the object returned is here:
    https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wmiiprouteprov/win32-ip4routetable

    The primary route metric is found in the property "Metric2". The remaining metric properties are for alternate routes.

    If you have an interface metric in the CIM data but not in the PowerShell output the problem may be in PowerShell or .Net. If it's not present in the CIM data you may have a problem with the WMI repository.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    First thanks. I agree, something is amiss.

    I ran "gwmi win32_IP4RouteTable", and the real metric for me is "Metric1          : 271"

    Thanks for the great lead


    Sunday, July 19, 2020 11:57 PM