Set-NetRoute

Set-NetRoute

Modifies an entry or entries in the IP routing table.

Syntax

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

Parameter Set: InputObject (cdxml)
Set-NetRoute -InputObject <CimInstance[]> [-AsJob] [-CimSession <CimSession[]> ] [-PassThru] [-PreferredLifetime <TimeSpan> ] [-Publish <Publish> ] [-RouteMetric <UInt16> ] [-ThrottleLimit <Int32> ] [-ValidLifetime <TimeSpan> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Detailed Description

The Set-NetRoute cmdlet modifies an entry or entries in the IP routing table. This cmdlet has 2 types of parameters. One set of parameters specifies the routing table entry or entries to be modified. A destination prefix must be used and next hop address must be used as an identifier and additional properties may be included such as InterfaceIndex. The second set of parameters modifies properties in that NetIPAddress object. These properties include Type, PrefixLength, valid or preferred lifetime and skip as source.

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.

NetRoute objects do not allow the DestinationPrefix or NextHop properties to be modified after creation. To modify these values, remove the NetRoute object and re-create it using the New-NetRoute cmdlet.

Note: A gateway is a routing concept covered by the Get-NetRoute cmdlet. For IP end points, 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, the Get-NetRoute cmdlet modifies the routing table for all of the routes on the computer.

Parameters

-AddressFamily<AddressFamily[]>

Specifies the IP address family of the IP route. 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

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 the IP route information by the destination orefix. This parameter value contains an IP address prefix and a prefix length, separated by a slash (/). A destination prefix of 0.0.0.0/0 for IPv4 or ::/0 for IPv6 would indicate that the NextHop parameter value is a default gateway.

Aliases

none

Required?

false

Position?

1

Default Value

dhcp

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InputObject<CimInstance[]>

Specifies the input to this cmdlet. You can use this parameter, or you can pipe the input to this cmdlet.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

-InterfaceAlias<String[]>

Specifies the interface on which the IP route is configured, as defined by the InterfaceAlias property.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-InterfaceIndex<UInt32[]>

Specifies the interface on which the IP route is configured, as defined by the InterfaceIndex number.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-NextHop<String[]>

Specifies the next hop used in the IP route. This parameter value is the IP address of the next hop in the route. A next hop 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

-PassThru

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

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>

Modifies the preferred lifetime of the IP route. 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>

Modifies the publish setting of the IP route. The acceptable values for this parameter are:
-- No: The IP Route information is not published nor advertised in router advertisements.
-- Yes: The IP Route information is published and advertised in router advertisements with an infinite ValidLifetime parameter.
-- Age: The IP Route information is published and advertised in router advertisements with a finite ValidLifetime parameter.
The default value is No.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-RouteMetric<UInt16>

Modifies the metric associated with the IP route. 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>

Modifies the valid lifetime of a route. 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

-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 (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

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

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

    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.

Outputs

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

  • None

Examples

EXAMPLE 1

This example sets the RouteMetric parameter to 257, making the route less preferable than the default of 256.

PS C:\> Set-NetRoute –RouteMetric 257

EXAMPLE 2

This example sets the PreferredLifetime parameter to one (1) day.

PS C:\> $timespan = ( New-TimeSpan –Days 1 )
PS C:\> Set-NetRoute –DestinationPrefix 192.168.0.0/24 –PreferredLifetime $timespan

Get-NetRoute

New-NetRoute

Remove-NetRoute

New-TimeSpan