Export (0) Print
Expand All

New-NetRoute

Applies To: Windows Server 2012

New-NetRoute

Creates an entry in the IP routing table.

Syntax

Parameter Set: ByInterfaceAlias
New-NetRoute [-DestinationPrefix] <String> -InterfaceAlias <String> [-AddressFamily <AddressFamily> ] [-AsJob] [-CimSession <CimSession[]> ] [-NextHop <String> ] [-PolicyStore <String> ] [-PreferredLifetime <TimeSpan> ] [-Publish <Publish> ] [-RouteMetric <UInt16> ] [-ThrottleLimit <Int32> ] [-ValidLifetime <TimeSpan> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: ByInterfaceIndex
New-NetRoute [-DestinationPrefix] <String> -InterfaceIndex <UInt32> [-AddressFamily <AddressFamily> ] [-AsJob] [-CimSession <CimSession[]> ] [-NextHop <String> ] [-PolicyStore <String> ] [-PreferredLifetime <TimeSpan> ] [-Publish <Publish> ] [-RouteMetric <UInt16> ] [-ThrottleLimit <Int32> ] [-ValidLifetime <TimeSpan> ] [-Confirm] [-WhatIf] [ <CommonParameters>]




Detailed Description

The New-NetRoute cmdlet creates an entry in the IP routing table, including properties such as 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 the NetRoute cmdlets. 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.

Parameters

-AddressFamily<AddressFamily>

Specifies the IP address family for the IP routing table entry. 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

-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>

Specifies a DestinationPrefix for the IP routing table entry. The DestinationPrefix 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. The PrefixLength must match the prefix specified in the DestinationPrefix, with all remaining address fields set to zero.


Aliases

none

Required?

true

Position?

1

Default Value

dhcp

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InterfaceAlias<String>

Specifies the interface to which the IP routing table entry applies, as defined by the interface alias.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-InterfaceIndex<UInt32>

Specifies the interface to which the IP routing table entry applies, as defined by the InterfaceIndex number.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-NextHop<String>

Specifies a next hop for the IP routing table entry. The NextHop 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. When the new routing table entry is created, the next hop IP address is also added as a neighbor cache entry.


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>

Specifies a preferred lifetime for the IP routing table entry. When not specified this parameter is set as infinite. This parameter 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>

Specifies the Publish setting for the IP routing table entry. The acceptable values for this parameter are: 
-- No: The IP Route information is published and advertised in router advertisements with an infinite ValidLifetime. This is the default.
-- Yes: The IP Route information is published and advertised in router advertisements with an infinite ValidLifetime.
-- Age: The IP Route information is published and advertised in router advertisements with a finite ValidLifetime.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-RouteMetric<UInt16>

Specifies the route metric for the IP routing table entry. 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>

Specifies a ValidLifetime for the IP routing table entry. When not specified the ValidLifetime is set as infinite. ValidLifetime 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

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

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 adds an IP routing table entry.


 

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


PS C:\> New-NetRoute –InterfaceIndex 12 –DestinationPrefix 10.0.0.0/24 –NextHop 192.168.0.1

 

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 *

Related topics

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft