Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Get-NetRoute

Applies To: Windows Server 2012

Get-NetRoute

Gets the IP routing table.

Syntax

Parameter Set: ByName
Get-NetRoute [[-DestinationPrefix] <String[]> ] [-AddressFamily <AddressFamily[]> ] [-AsJob] [-AssociatedIPInterface <CimInstance> ] [-CimSession <CimSession[]> ] [-InterfaceAlias <String[]> ] [-InterfaceIndex <UInt32[]> ] [-NextHop <String[]> ] [-PolicyStore <String> ] [-PreferredLifetime <TimeSpan[]> ] [-Publish <Publish[]> ] [-RouteMetric <UInt16[]> ] [-ThrottleLimit <Int32> ] [-ValidLifetime <TimeSpan[]> ] [ <CommonParameters>]




Detailed Description

The Get-NetRoute cmdlet gets the IP routing table information, including destination network prefixes, Next Hop IP addresses and Route Metrics.

IP routing is the process of forwarding a packet based on the destination IP address. Routing occurs at a sending TCP/IP host and at an IP router.
In each case, the IP layer at the sending host or router must decide where to forward the packet. For IPv4, routers are also commonly referred to as gateways. To make these decisions, the IP layer consults a routing table stored in memory. Routing table entries are created by default when TCP/IP initializes, and entries can be added either manually or automatically. When the computer is routing, the RouteMetric property is added to the InterfaceMetric property, described as a part of NetIPInterface. This total value is used to decide the pass-through interface to send the forwarded packets. For more information, see IP Routing on TechNet.

Note: A gateway is a routing concept covered by this cmdlet. For IP endpoints, the gateway specifies the forwarding or next hop IP address over which the set of addresses defined by the network destination and subnet mask are reachable.

Without parameters, this cmdlet returns the routing table for all routes on the computer.

Parameters

-AddressFamily<AddressFamily[]>

Gets IP routes by IP address family. The acceptable values for this parameter are: 
-- IPv4: IPv4 route information.
-- IPv6: IPv6 route information.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-AsJob

Runs the cmdlet as a background job. Use this parameter to run commands that take a long time to complete. The cmdlet immediately returns an object that represents the job and then displays the command prompt. You can continue to work in the session while the job completes. To manage the job, use the *-Job cmdlets. To get the job results, use the Receive-Job cmdlet. For more information about Windows PowerShell® background jobs, see about_Jobs.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-AssociatedIPInterface<CimInstance>

Gets IP routes by a specific network IP interface CIM object. This is typically as input through the pipeline.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

-CimSession<CimSession[]>

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DestinationPrefix<String[]>

Gets IP routes by destination prefix. This parameter value contains an IP address prefix and a prefix length, separated by a slash (/). A DestinationPrefix of 0.0.0.0/0 for IPv4 or ::/0 for IPv6 would indicate that the NextHop is a default gateway.


Aliases

none

Required?

false

Position?

1

Default Value

dhcp

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InterfaceAlias<String[]>

Gets IP routes by a specific interface, as defined by the interface alias.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-InterfaceIndex<UInt32[]>

Gets IP routes by a specific interface, as defined by the InterfaceIndex number.Specifies the user-friendly interface index number.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-NextHop<String[]>

Gets IP routes by next hop. This parameter value is the IP address of the next hop in the route. A NextHop of 0.0.0.0 for IPv4 or :: for IPv6 would indicate that the route is on-link.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-PolicyStore<String>

Specifies the PolicyStore value. The acceptable values for this parameter are: 
-- ActiveStore: The IP address information is currently valid.
-- PersistentStore: The IP address information is persistent across reboots. When the computer starts, the PersistentStore settings are copied to the ActiveStore.
The default value is ActiveStore.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-PreferredLifetime<TimeSpan[]>

Gets IP routes by preferred lifetime. This parameter value uses time as defined by the TimeSpan structure.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Publish<Publish[]>

Gets the IP routes by publish property. By default, routes are not published and thus not advertised in Router Advertisements (No). This is the default. Routes may be published (Yes) and advertised in router advertisements with an infinite ValidLifetime. Routes may also be published (Age) and advertised in Router Advertisements with a finite ValidLifetime. The acceptable values for this parameter are: 
-- No: The IP Route information is currently from unpublished routes.
-- Yes: The IP Route information is currently from published routes with an infinite lifetime.
-- Age: The IP Route information is currently from published routes with a finite lifetime.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-RouteMetric<UInt16[]>

Gets IP routes by route metric. This parameter value specifies an integer cost metric for the route. This parameter value is added to the InterfaceMetric parameter value and the total value is used when choosing among multiple routes in the routing table that most closely match the destination address of a packet being forwarded. The route with the lowest, combined RouteMetric property and InterfaceMetric property value is chosen.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ThrottleLimit<Int32>

Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ValidLifetime<TimeSpan[]>

Gets IP routes by valid lifetime. This parameter value uses time as defined by the TimeSpan structure.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters.

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

Outputs

The output type is the type of the objects that the cmdlet emits.

  • Microsoft.Management.Infrastructure.CimInstance#root\StandardCimv2\MSFT_NetRoute

    The Microsoft.Management.Infrastructure.CimInstance object is a wrapper class that displays Windows Management Instrumentation (WMI) objects. The path after the pound sign (#) provides the namespace and class name for the underlying WMI object.


Examples

EXAMPLE 1

This example gets information about IP route configuration.


 

Used without parameters, this cmdlet gets IP route information for all interfaces.


PS C:\> Get-NetRoute

 

The default output omits some properties. Run this cmdlet to display all of the fields (all of the properties of the object).


PS C:\> Get-NetRoute | Format-List –Property *

EXAMPLE 2

This example gets information about the IP route configuration for IPv6 routes.


PS C:\> Get-NetRoute –AddressFamily IPv6

EXAMPLE 3

This example gets information about IP route configuration, and displays more information than the default table view. This includes properties such as InterfaceAlias, ValidLifetime, and PreferredLifetime.


PS C:\> Get-NetRoute | Format-List

EXAMPLE 4

This example gets information about IP route configuration for all routes that use a specific InterfaceIndex.


PS C:\> Get-NetRoute –InterfaceIndex 12

EXAMPLE 4

This example gets the default IP routes, finds one or more NextHop IP addresses, and displays them. Note: The next hop gateway for the default route is also known as the default gateway.


PS C:\> Get-NetRoute –DestinationPrefix "0.0.0.0/0" | Select-Object –Expand NextHop

EXAMPLE 5

This example gets information about IP routes that access destinations off-link.


PS C:\> Get-NetRoute | Where-Object –FilterScript { $_.NextHop -Ne "::" } | Where-Object –FilterScript { $_.NextHop -Ne "0.0.0.0" } | Where-Object –FilterScript { ($_.NextHop.SubString(0,6) -Ne "fe80::") }

EXAMPLE 6

This example gets information about network adapters that have IP routes that access destinations off-link.


PS C:\> Get-NetRoute | Where-Object –FilterScript {$_.NextHop -Ne "::"} | Where-Object –FilterScript { $_.NextHop -Ne "0.0.0.0" } | Where-Object –FilterScript { ($_.NextHop.SubString(0,6) -Ne "fe80::") } | Get-NetAdapter

EXAMPLE 7

This example gets information about IP Routes that have an infinite ValidLifetime.


 

PS C:\> Get-NetRoute | Where-Object –FilterScript { $_.ValidLifetime -Eq ([TimeSpan]::MaxValue) }

 

Similarly, this command gets information about IP Routes that do not have an infinite ValidLifetime.


PS C:\> Get-NetRoute | Where-Object –FilterScript { $_.ValidLifetime -Ne ([TimeSpan]::MaxValue) }

Related topics

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.