New-NetRoute

New-NetRoute

Creates a route in the IP routing table.

Syntax

Parameter Set: ByInterfaceAlias
New-NetRoute [-DestinationPrefix] <String> -InterfaceAlias <String> [-AddressFamily <AddressFamily> {IPv4 | IPv6} ] [-CimSession <CimSession[]> ] [-NextHop <String> ] [-PolicyStore <String> ] [-PreferredLifetime <TimeSpan> ] [-Protocol <Protocol> {Other | Local | NetMgmt | Icmp | Egp | Ggp | Hello | Rip | IsIs | EsIs | Igrp | Bbn | Ospf | Bgp | Idpr | Eigrp | Dvmrp | Rpl | Dhcp} ] [-Publish <Publish> {No | Age | Yes} ] [-RouteMetric <UInt16> ] [-ThrottleLimit <Int32> ] [-ValidLifetime <TimeSpan> ] [-Confirm] [-WhatIf] [ <CommonParameters>] [ <WorkflowParameters>]

Parameter Set: ByInterfaceIndex
New-NetRoute [-DestinationPrefix] <String> -InterfaceIndex <UInt32> [-AddressFamily <AddressFamily> {IPv4 | IPv6} ] [-CimSession <CimSession[]> ] [-NextHop <String> ] [-PolicyStore <String> ] [-PreferredLifetime <TimeSpan> ] [-Protocol <Protocol> {Other | Local | NetMgmt | Icmp | Egp | Ggp | Hello | Rip | IsIs | EsIs | Igrp | Bbn | Ospf | Bgp | Idpr | Eigrp | Dvmrp | Rpl | Dhcp} ] [-Publish <Publish> {No | Age | Yes} ] [-RouteMetric <UInt16> ] [-ThrottleLimit <Int32> ] [-ValidLifetime <TimeSpan> ] [-Confirm] [-WhatIf] [ <CommonParameters>] [ <WorkflowParameters>]

Detaillierte Beschreibung

The New-NetRoute cmdlet creates an IP route in the IP routing table. Specify the destination prefix, and specify an interface by using the interface alias or the interface index.

IP routing is the process of forwarding a packet based on the destination IP address. Routing occurs at TCP/IP hosts and at IP routers. The sending host or router determines where to forward the packet. To determine where to forward a packet, the host or router consults a routing table that is stored in memory. When TCP/IP starts, it creates entries in the routing table. You can add entries either manually or automatically.

For more information about routing, see Chapter 5 - IP Routing (https://technet.microsoft.com/library/bb727001.aspx) in the TechNet library.

Parameter

-AddressFamily<AddressFamily>

Specifies the IP address family. The cmdlet uses the family that you specify for the IP route. Die zulässigen Werte für diesen Parameter sind:

-- IPv4
-- IPv6

If you do not specify this parameter, the cmdlet selects a value based on the other input that you provide.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-CimSession<CimSession[]>

Das Cmdlet wird in einer Remotesitzung oder auf einem Remotecomputer ausgeführt. Geben Sie einen Computernamen oder ein Sitzungsobjekt ein, wie z. B. die Ausgabe eines New-CimSession oder Get-CimSession-Cmdlets. Der Standardwert ist die aktuelle Sitzung auf dem lokalen Computer.

Aliase

Session

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-DestinationPrefix<String>

Specifies a destination prefix of an IP route. A destination prefix consists of an IP address prefix and a prefix length, separated by a slash (/). A value of 0.0.0.0/0 for IPv4 or ::/0 for IPv6 indicates that the value of the NextHop parameter is a default gateway. The prefix length of the local host must match the prefix specified in this parameter, with all remaining address fields set to zero.

Aliase

none

Erforderlich?

true

Position?

1

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-InterfaceAlias<String>

Specifies the alias of a network interface. The cmdlet adds a route for the interface that has the alias that you specify.

Aliase

ifAlias

Erforderlich?

true

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

True (ByPropertyName)

Platzhalterzeichen akzeptieren?

false

-InterfaceIndex<UInt32>

Specifies the index of a network interface. The cmdlet adds a route for the interface located at the index that you specify.

Aliase

ifIndex

Erforderlich?

true

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

True (ByPropertyName)

Platzhalterzeichen akzeptieren?

false

-NextHop<String>

Specifies the next hop for the IP route. The cmdlet assigns the next hop that you specify to the IP route. A value of 0.0.0.0 for IPv4 or :: for IPv6 indicates that the route is on the local subnet.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-PolicyStore<String>

Specifies the PolicyStore value. The cmdlet assigns the PolicyStore value that you specify to the IP route. Die zulässigen Werte für diesen Parameter sind:

-- ActiveStore. The IP address information is valid.
-- PersistentStore. The computer saves IP address information across restarts. When the computer restarts, it copies the saved settings to the ActiveStore.

The default value is ActiveStore. Specify ActiveStore only.

If you do not specify this parameter, the default entries are created in both the ActiveStore and the PersistentStore.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-PreferredLifetime<TimeSpan>

Specifies a preferred lifetime, as a TimeSpan object, of an IP route.The cmdlet assigns the lifetime that you specify to the IP route. To obtain a TimeSpan object, use the New-TimeSpan cmdlet. For more information, type Get-Help New-TimeSpan. The default value for a lifetime is infinite.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-Protocol<Protocol>

Specifies the type of routing protocol. The cmdlet assigns the protocol that you specify to the IP route. Die zulässigen Werte für diesen Parameter sind:

-- Bbn
-- Bgp
-- Dhcp
-- Dvmrp
-- Egp
-- Eigrp
-- EsIs
-- Ggp
-- Hello
-- Icmp
-- Idpr
-- Igrp
-- IsIs
-- Local
-- NetMgmt
-- Ospf
-- Rip
-- Rpl
-- Other

The default value is NetMgmt.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-Publish<Publish>

Specifies the publish setting of an IP route. The cmdlet assigns the publish setting that you specify to the IP route. Die zulässigen Werte für diesen Parameter sind:

-- No. Do not publish or advertise IP route information in router advertisements.
-- Yes. Publish and advertise IP route information with an infinite valid lifetime in router advertisements.
-- Age. Publish and advertise IP route information with a finite valid lifetime in router advertisements. Specify a valid lifetime by using the ValidLifetime parameter.

The default value is No.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-RouteMetric<UInt16>

Specifies an integer route metric for an IP route. The cmdlet assigns the metric that you specify to the IP route. The default value is 256. To choose among multiple routes, the computer adds this value. The computer selects the route with the lowest combined value. To modify the interface metric, use the Set-NetIPInterface cmdlet.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-ThrottleLimit<Int32>

Gibt die maximale Anzahl gleichzeitiger Vorgänge an, die zum Ausführen des Cmdlets hergestellt werden können. Wenn dieser Parameter ausgelassen wird oder der Wert 0 eingegeben wird, berechnet Windows PowerShell ® einen optimalen Drosselungsgrenzwert für das Cmdlet basierend auf der Anzahl der CIM-Cmdlets, die auf dem Computer ausgeführt werden. Der Grenzwert gilt nur für das aktuelle Cmdlet, nicht für die Sitzung oder den Computer.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-ValidLifetime<TimeSpan>

Specifies a valid lifetime, as a TimeSpan object, for an IP route. The cmdlet assigns the lifetime setting that you specify to the IP route. To obtain a TimeSpan object, use the New-TimeSpan cmdlet. The default value is infinite.

Aliase

none

Erforderlich?

false

Position?

named

Standardwert

none

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-Confirm

Fordert Sie vor der Ausführung des Cmdlet zum Bestätigen auf.

Erforderlich?

false

Position?

named

Standardwert

false

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

-WhatIf

Zeit, was passieren würde, wenn das Cmdlet ausgeführt wird. Das Cmdlet wird nicht ausgeführt.

Erforderlich?

false

Position?

named

Standardwert

false

Pipelineeingaben akzeptieren?

false

Platzhalterzeichen akzeptieren?

false

<CommonParameters>

Dieses Cmdlet unterstützt die allgemeinen Parameter: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer und -OutVariable. Weitere Informationen finden Sie unter about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

<WorkflowParameters>

Eingaben

Der Eingabetyp ist der Typ der Objekte, die Sie per Piping an das Cmdlet übergeben können.

  • None

Ausgaben

Der Ausgabetyp ist der Typ der Objekte, die vom Cmdlet ausgegeben werden.

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

    Das Microsoft.Management.Infrastructure.CimInstance-Objekt ist eine Wrapperklasse, die Windows-Verwaltungsinstrumentation-Objekte (Windows Management Instrumentation, WMI) angezeigt. Der Pfad nach dem Nummernzeichen (#) stellt den Namespace und den Klassennamen des zugrunde liegenden WMI-Objekts dar.

Beispiele

Example 1: Add an IP route to the routing table

This example adds a routing table entry, and then displays the properties of all the entries in the routing table.

The first command creates a route for the destination prefix 10.0.0.0/24 for the interface that has the index of 12. The command specifies 192.168.0.1 as the next hop.

The second command uses the Get-NetRoute cmdlet to get all the routes for the computer, and then passes them to the Format-List cmdlet by using the pipeline operator. The Format-List cmdlet can display all the properties of an object. For more information, type Get-Help Format-List.

PS C:\> New-NetRoute –DestinationPrefix "10.0.0.0/24" –InterfaceIndex 12 –NextHop 192.168.0.1
PS C:\> Get-NetRoute | Format-List -Property *

Verwandte Themen

Find-NetRoute

Get-NetRoute

Remove-NetRoute

Set-NetRoute

Set-NetIPInterface