The Win32_IP4RouteTable WMI class represents information that governs the routing of network data packets. For example, Internet packets are usually sent to a gateway and local packets are routed directly by the client computer. Administrators can use this information to trace problems associated with misrouted packets, and also direct a computer to a new gateway as necessary. This class only represents the information shown as a result of typing the route print command from the command prompt. This class is only applicable to IPv4 and does not return IPX or IPv6 data. For more information, see IPv6 and IPv4 Support in WMI.
Methods
Win32_IP4RouteTable has no methods.
Properties
Win32_IP4RouteTable returns 18 properties:
'Age','Caption','Description','Destination','Information','InstallDate',
'InterfaceIndex','Mask','Metric1','Metric2','Metric3','Metric4','Metric5','Name','NextHop','Protocol',
'Status','Type'
Unless explicitly marked as writeable, all properties are read-only. Read all properties for all instances:
Get-CimInstance -ClassName Win32_IP4RouteTable -Property *
Most WMI classes return one or more instances.
When
Get-CimInstance
returns no result, then apparently no instances of class Win32_IP4RouteTable exist. This is normal behavior.Either the class is not implemented on your system (may be deprecated or due to missing drivers, i.e. CIM_VideoControllerResolution), or there are simply no physical representations of this class currently available (i.e. Win32_TapeDrive).
Age
Number of seconds since this route was last updated or otherwise determined to be correct. Whether the routing information is outdated can only be determined by knowing the routing protocol by which the route was learned.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Age
Caption
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Caption
Description
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Description
Destination
Destination IP address for this route.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop
Information
Reference to Management Information Base (MIB) definitions specific to the particular routing protocol that handles this route, as determined by the value specified in the route ipRouteProto value. If this information is not present, its value should be set to the OBJECT IDENTIFIER {0 0}, which is a syntactically valid object identifier, and any conforming implementation of ASN.1 and BER must be able to generate and recognize this value.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Information
InstallDate
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, InstallDate
InterfaceIndex
IP address of the next hop of this route. The value in this property is the same as the value in the InterfaceIndex property in the instances of Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration that represent the network interface of the next hop of the route.
In the case of a route bound to an interface that is realized using a broadcast medium, the value of this field is the agent IP address on that interface.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop
Mask
Mask used in this entry. Masks should be joined with a logical AND to the destination address before being compared to the value in the ipRouteDest field.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop
Metric1
Primary routing metric for this route. The routing protocol specified in the ipRouteProto value for the route determines the interpretation of this property. Set the value of this property to -1 if it is not used.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Metric1
Metric2
Alternate routing metric for this route. The routing protocol specified in the ipRouteProto value for the route determines the interpretation of this property. Set the value of this property to -1 if it is not used.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Metric2
Metric3
Alternate routing metric for this route. The routing protocol specified in the ipRouteProto value for the route determines the interpretation of this property. Set the value of this property to -1 if it is not used.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Metric3
Metric4
Alternate routing metric for this route. The routing protocol specified in the ipRouteProto value for the route determines the interpretation of this property. Set the value of this property to -1 if it is not used.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Metric4
Metric5
Alternate routing metric for this route. The routing protocol specified in the ipRouteProto value for the route determines the interpretation of this property. Set the value of this property to -1 if it is not used.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Metric5
Name
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Name
NextHop
IP address of the next hop of this route. For a route that is bound to an interface realized via a broadcast medium, the value of this field is the agent IP address on that interface.
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop
Protocol
Routing mechanism through which this route was learned. Inclusion of values for gateway routing protocols does not imply that hosts must support those protocols.
Protocol returns a numeric value. To translate it into a meaningful text, use any of the following approaches:
Use a PowerShell Hashtable
$Protocol_map = @{
1 = 'other'
2 = 'local'
3 = 'netmgmt'
4 = 'icmp'
5 = 'egp'
6 = 'ggp'
7 = 'hello'
8 = 'rip'
9 = 'is-is'
10 = 'es-is'
11 = 'ciscoIgrp'
12 = 'bbnSpfIgp'
13 = 'ospf'
14 = 'bgp'
}
Use a switch statement
switch([int]$value)
{
1 {'other'}
2 {'local'}
3 {'netmgmt'}
4 {'icmp'}
5 {'egp'}
6 {'ggp'}
7 {'hello'}
8 {'rip'}
9 {'is-is'}
10 {'es-is'}
11 {'ciscoIgrp'}
12 {'bbnSpfIgp'}
13 {'ospf'}
14 {'bgp'}
default {"$value"}
}
Use Enum structure
Enum EnumProtocol
{
other = 1
local = 2
netmgmt = 3
icmp = 4
egp = 5
ggp = 6
hello = 7
rip = 8
is_is = 9
es_is = 10
ciscoIgrp = 11
bbnSpfIgp = 12
ospf = 13
bgp = 14
}
Examples
Use $Protocol_map in a calculated property for Select-Object
<#
this example uses a hashtable to translate raw numeric values for
property "Protocol" to friendly text
Note: to use other properties than "Protocol", look up the appropriate
translation hashtable for the property you would like to use instead.
#>
#region define hashtable to translate raw values to friendly text
# Please note: this hashtable is specific for property "Protocol"
# to translate other properties, use their translation table instead
$Protocol_map = @{
1 = 'other'
2 = 'local'
3 = 'netmgmt'
4 = 'icmp'
5 = 'egp'
6 = 'ggp'
7 = 'hello'
8 = 'rip'
9 = 'is-is'
10 = 'es-is'
11 = 'ciscoIgrp'
12 = 'bbnSpfIgp'
13 = 'ospf'
14 = 'bgp'
}
#endregion define hashtable
#region define calculated property (to be used with Select-Object)
<#
a calculated property is defined by a hashtable with keys "Name" and "Expression"
"Name" defines the name of the property (in this example, it is "Protocol", but you can rename it to anything else)
"Expression" defines a scriptblock that calculates the content of this property
in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
value to its friendly text counterpart:
#>
$Protocol = @{
Name = 'Protocol'
Expression = {
# property is an array, so process all values
$value = $_.Protocol
$Protocol_map[[int]$value]
}
}
#endregion define calculated property
# retrieve the instances, and output the properties "Caption" and "Protocol". The latter
# is defined by the hashtable in $Protocol:
Get-CimInstance -Class Win32_IP4RouteTable | Select-Object -Property Caption, $Protocol
# ...or dump content of property Protocol:
$friendlyValues = Get-CimInstance -Class Win32_IP4RouteTable |
Select-Object -Property $Protocol |
Select-Object -ExpandProperty Protocol
# output values
$friendlyValues
# output values as comma separated list
$friendlyValues -join ', '
# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $Protocol_map to directly translate raw values from an instance
<#
this example uses a hashtable to manually translate raw numeric values
for property "Win32_IP4RouteTable" to friendly text. This approach is ideal when
there is just one instance to work with.
Note: to use other properties than "Win32_IP4RouteTable", look up the appropriate
translation hashtable for the property you would like to use instead.
#>
#region define hashtable to translate raw values to friendly text
# Please note: this hashtable is specific for property "Win32_IP4RouteTable"
# to translate other properties, use their translation table instead
$Protocol_map = @{
1 = 'other'
2 = 'local'
3 = 'netmgmt'
4 = 'icmp'
5 = 'egp'
6 = 'ggp'
7 = 'hello'
8 = 'rip'
9 = 'is-is'
10 = 'es-is'
11 = 'ciscoIgrp'
12 = 'bbnSpfIgp'
13 = 'ospf'
14 = 'bgp'
}
#endregion define hashtable
# get one instance:
$instance = Get-CimInstance -Class Win32_IP4RouteTable | Select-Object -First 1
<#
IMPORTANT: this example processes only one instance to illustrate
the number-to-text translation. To process all instances, replace
"Select-Object -First 1" with a "Foreach-Object" loop, and use
the iterator variable $_ instead of $instance
#>
# query the property
$rawValue = $instance.Protocol
# translate raw value to friendly text:
$friendlyName = $Protocol_map[[int]$rawValue]
# output value
$friendlyName
Use a switch statement inside a calculated property for Select-Object
<#
this example uses a switch clause to translate raw numeric
values for property "Protocol" to friendly text. The switch
clause is embedded into a calculated property so there is
no need to refer to external variables for translation.
Note: to use other properties than "Protocol", look up the appropriate
translation switch clause for the property you would like to use instead.
#>
#region define calculated property (to be used with Select-Object)
<#
a calculated property is defined by a hashtable with keys "Name" and "Expression"
"Name" defines the name of the property (in this example, it is "Protocol", but you can rename it to anything else)
"Expression" defines a scriptblock that calculates the content of this property
in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
value to its friendly text counterpart:
#>
$Protocol = @{
Name = 'Protocol'
Expression = {
# property is an array, so process all values
$value = $_.Protocol
switch([int]$value)
{
1 {'other'}
2 {'local'}
3 {'netmgmt'}
4 {'icmp'}
5 {'egp'}
6 {'ggp'}
7 {'hello'}
8 {'rip'}
9 {'is-is'}
10 {'es-is'}
11 {'ciscoIgrp'}
12 {'bbnSpfIgp'}
13 {'ospf'}
14 {'bgp'}
default {"$value"}
}
}
}
#endregion define calculated property
# retrieve all instances...
Get-CimInstance -ClassName Win32_IP4RouteTable |
# ...and output properties "Caption" and "Protocol". The latter is defined
# by the hashtable in $Protocol:
Select-Object -Property Caption, $Protocol
Use the Enum from above to auto-translate the code values
<#
this example translates raw values by means of type conversion
the friendly names are defined as enumeration using the
keyword "enum" (PowerShell 5 or better)
The raw value(s) are translated to friendly text by
simply converting them into the enum type.
Note: to use other properties than "Win32_IP4RouteTable", look up the appropriate
enum definition for the property you would like to use instead.
#>
#region define enum with value-to-text translation:
Enum EnumProtocol
{
other = 1
local = 2
netmgmt = 3
icmp = 4
egp = 5
ggp = 6
hello = 7
rip = 8
is_is = 9
es_is = 10
ciscoIgrp = 11
bbnSpfIgp = 12
ospf = 13
bgp = 14
}
#endregion define enum
# get one instance:
$instance = Get-CimInstance -Class Win32_IP4RouteTable | Select-Object -First 1
<#
IMPORTANT: this example processes only one instance to focus on
the number-to-text type conversion.
To process all instances, replace "Select-Object -First 1"
with a "Foreach-Object" loop, and use the iterator variable
$_ instead of $instance
#>
# query the property:
$rawValue = $instance.Protocol
#region using strict type conversion
<#
Note: strict type conversion fails if the raw value is
not defined by the enum. So if the list of allowable values
was extended and the enum does not match the value,
an exception is thrown
#>
# convert the property to the enum **Protocol**
[EnumProtocol]$rawValue
# get a comma-separated string:
[EnumProtocol]$rawValue -join ','
#endregion
#region using operator "-as"
<#
Note: the operator "-as" accepts values not defined
by the enum and returns $null instead of throwing
an exception
#>
$rawValue -as [EnumProtocol]
#endregion
Enums must cover all possible values. If Protocol returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.
Status
Current status of an object. Various operational and nonoperational statuses can be defined. Available values:
$values = 'Degraded','Error','Lost Comm','No Contact','NonRecover','OK','Pred Fail','Service','Starting','Stopping','Stressed','Unknown'
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property Destination, InterfaceIndex, Mask, NextHop, Status
Type
Type of route. The following list lists the values.
Type returns a numeric value. To translate it into a meaningful text, use any of the following approaches:
Use a PowerShell Hashtable
$Type_map = @{
1 = 'other'
2 = 'invalid'
3 = 'direct'
4 = 'indirect'
}
Use a switch statement
switch([int]$value)
{
1 {'other'}
2 {'invalid'}
3 {'direct'}
4 {'indirect'}
default {"$value"}
}
Use Enum structure
Enum EnumType
{
other = 1
invalid = 2
direct = 3
indirect = 4
}
Examples
Use $Type_map in a calculated property for Select-Object
<#
this example uses a hashtable to translate raw numeric values for
property "Type" to friendly text
Note: to use other properties than "Type", look up the appropriate
translation hashtable for the property you would like to use instead.
#>
#region define hashtable to translate raw values to friendly text
# Please note: this hashtable is specific for property "Type"
# to translate other properties, use their translation table instead
$Type_map = @{
1 = 'other'
2 = 'invalid'
3 = 'direct'
4 = 'indirect'
}
#endregion define hashtable
#region define calculated property (to be used with Select-Object)
<#
a calculated property is defined by a hashtable with keys "Name" and "Expression"
"Name" defines the name of the property (in this example, it is "Type", but you can rename it to anything else)
"Expression" defines a scriptblock that calculates the content of this property
in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
value to its friendly text counterpart:
#>
$Type = @{
Name = 'Type'
Expression = {
# property is an array, so process all values
$value = $_.Type
$Type_map[[int]$value]
}
}
#endregion define calculated property
# retrieve the instances, and output the properties "Caption" and "Type". The latter
# is defined by the hashtable in $Type:
Get-CimInstance -Class Win32_IP4RouteTable | Select-Object -Property Caption, $Type
# ...or dump content of property Type:
$friendlyValues = Get-CimInstance -Class Win32_IP4RouteTable |
Select-Object -Property $Type |
Select-Object -ExpandProperty Type
# output values
$friendlyValues
# output values as comma separated list
$friendlyValues -join ', '
# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $Type_map to directly translate raw values from an instance
<#
this example uses a hashtable to manually translate raw numeric values
for property "Win32_IP4RouteTable" to friendly text. This approach is ideal when
there is just one instance to work with.
Note: to use other properties than "Win32_IP4RouteTable", look up the appropriate
translation hashtable for the property you would like to use instead.
#>
#region define hashtable to translate raw values to friendly text
# Please note: this hashtable is specific for property "Win32_IP4RouteTable"
# to translate other properties, use their translation table instead
$Type_map = @{
1 = 'other'
2 = 'invalid'
3 = 'direct'
4 = 'indirect'
}
#endregion define hashtable
# get one instance:
$instance = Get-CimInstance -Class Win32_IP4RouteTable | Select-Object -First 1
<#
IMPORTANT: this example processes only one instance to illustrate
the number-to-text translation. To process all instances, replace
"Select-Object -First 1" with a "Foreach-Object" loop, and use
the iterator variable $_ instead of $instance
#>
# query the property
$rawValue = $instance.Type
# translate raw value to friendly text:
$friendlyName = $Type_map[[int]$rawValue]
# output value
$friendlyName
Use a switch statement inside a calculated property for Select-Object
<#
this example uses a switch clause to translate raw numeric
values for property "Type" to friendly text. The switch
clause is embedded into a calculated property so there is
no need to refer to external variables for translation.
Note: to use other properties than "Type", look up the appropriate
translation switch clause for the property you would like to use instead.
#>
#region define calculated property (to be used with Select-Object)
<#
a calculated property is defined by a hashtable with keys "Name" and "Expression"
"Name" defines the name of the property (in this example, it is "Type", but you can rename it to anything else)
"Expression" defines a scriptblock that calculates the content of this property
in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
value to its friendly text counterpart:
#>
$Type = @{
Name = 'Type'
Expression = {
# property is an array, so process all values
$value = $_.Type
switch([int]$value)
{
1 {'other'}
2 {'invalid'}
3 {'direct'}
4 {'indirect'}
default {"$value"}
}
}
}
#endregion define calculated property
# retrieve all instances...
Get-CimInstance -ClassName Win32_IP4RouteTable |
# ...and output properties "Caption" and "Type". The latter is defined
# by the hashtable in $Type:
Select-Object -Property Caption, $Type
Use the Enum from above to auto-translate the code values
<#
this example translates raw values by means of type conversion
the friendly names are defined as enumeration using the
keyword "enum" (PowerShell 5 or better)
The raw value(s) are translated to friendly text by
simply converting them into the enum type.
Note: to use other properties than "Win32_IP4RouteTable", look up the appropriate
enum definition for the property you would like to use instead.
#>
#region define enum with value-to-text translation:
Enum EnumType
{
other = 1
invalid = 2
direct = 3
indirect = 4
}
#endregion define enum
# get one instance:
$instance = Get-CimInstance -Class Win32_IP4RouteTable | Select-Object -First 1
<#
IMPORTANT: this example processes only one instance to focus on
the number-to-text type conversion.
To process all instances, replace "Select-Object -First 1"
with a "Foreach-Object" loop, and use the iterator variable
$_ instead of $instance
#>
# query the property:
$rawValue = $instance.Type
#region using strict type conversion
<#
Note: strict type conversion fails if the raw value is
not defined by the enum. So if the list of allowable values
was extended and the enum does not match the value,
an exception is thrown
#>
# convert the property to the enum **Type**
[EnumType]$rawValue
# get a comma-separated string:
[EnumType]$rawValue -join ','
#endregion
#region using operator "-as"
<#
Note: the operator "-as" accepts values not defined
by the enum and returns $null instead of throwing
an exception
#>
$rawValue -as [EnumType]
#endregion
Enums must cover all possible values. If Type returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.
Examples
List all instances of Win32_IP4RouteTable
Get-CimInstance -ClassName Win32_IP4RouteTable
Learn more about Get-CimInstance
and the deprecated Get-WmiObject
.
View all properties
Get-CimInstance -ClassName Win32_IP4RouteTable -Property *
View key properties only
Get-CimInstance -ClassName Win32_IP4RouteTable -KeyOnly
Selecting Properties
To select only some properties, pipe the results to Select-Object -Property a,b,c
with a comma-separated list of the properties you require. Wildcards are permitted.
Get-CimInstance
always returns all properties but only retrieves the ones that you specify. All other properties are empty but still present. That’s why you need to pipe the results into Select-Object
if you want to limit the visible properties, i.e. for reporting.
Selecting Properties
The code below lists all available properties. Remove the ones you do not need:
$properties = 'Age',
'Caption',
'Description',
'Destination',
'Information',
'InstallDate',
'InterfaceIndex',
'Mask',
'Metric1',
'Metric2',
'Metric3',
'Metric4',
'Metric5',
'Name',
'NextHop',
'Protocol',
'Status',
'Type'
Get-CimInstance -ClassName Win32_IP4RouteTable | Select-Object -Property $properties
Limiting Network Bandwidth
If you work remotely, it makes sense to limit network bandwidth by filtering the properties on the server side, too:
Get-CimInstance -Class Win32_IP4RouteTable -Property $property |
Select-Object -Property $property
Selecting Instances
To select some instances, use Get-CimInstance and a WMI Query. The wildcard character in WMI Queries is % (and not “*”).
The parameter -Filter runs a simple query.
Listing all instances where the property Caption starts with “A”
Get-CimInstance -Class Win32_IP4RouteTable -Filter 'Caption LIKE "a%"'
Using a WQL Query
The parameter -Query uses a query similar to SQL and combines the parameters -Filter and -Property. This returns all instances where the property Caption starts with “A”, and returns the properties specified:
Get-CimInstance -Query "SELECT Mask, Caption, Age, Status FROM Win32_IP4RouteTable WHERE Caption LIKE 'a%'"
Any property you did not specify is still present but empty. You might need to use
Select-Object
to remove all unwanted properties:Get-CimInstance -Query "SELECT Mask, Caption, Age, Status FROM Win32_IP4RouteTable WHERE Caption LIKE 'a%'" | Select-Object -Property Mask, Caption, Age, Status
Accessing Remote Computers
To access remote systems, you need to have proper permissions. User the parameter -ComputerName to access one or more remote systems.
Authenticating as Current User
# one or more computer names or IP addresses:
$list = 'server1', 'server2'
# authenticate with your current identity:
$result = Get-CimInstance -ClassName Win32_IP4RouteTable -ComputerName $list
$result
Authenticating as Different User
Use a CIMSession object to authenticate with a new identity:
# one or more computer names or IP addresses:
$list = 'server1', 'server2'
# authenticate with a different identity:
$cred = Get-Credential -Message 'Authenticate to retrieve WMI information:'
$session = New-CimSession -ComputerName $list -Credential $cred
$result = Get-CimInstance Win32_IP4RouteTable -CimSession $session
# remove the session after use (if you do not plan to re-use it later)
Remove-CimSession -CimSession $session
$result
Learn more about accessing remote computers.
Requirements
To use Win32_IP4RouteTable, the following requirements apply:
PowerShell
Get-CimInstance
was introduced with PowerShell Version 3.0, which in turn was introduced on clients with Windows 8 and on servers with Windows Server 2012.
If necessary, update Windows PowerShell to Windows PowerShell 5.1, or install PowerShell 7 side-by-side.
Operating System
Win32_IP4RouteTable was introduced on clients with Windows Vista and on servers with Windows Server 2008.
Namespace
Win32_IP4RouteTable lives in the Namespace Root/CIMV2. This is the default namespace. There is no need to use the -Namespace parameter in Get-CimInstance
.
Implementation
Win32_IP4RouteTable is implemented in Wmipiprt.dll and defined in Wmipiprt.mof. Both files are located in the folder C:\Windows\system32\wbem
:
explorer $env:windir\system32\wbem
notepad $env:windir\system32\wbem\Wmipiprt.mof