SkillPilotAI

PowerShell NetTCPIP module (1/3)

The NetTCPIP module's Get-Net* cmdlets are the PowerShell way to read IP addresses, interfaces, routes, the neighbor (ARP) cache and global TCP/IP settings as objects. Built into Windows 10/11 and Server, in PowerShell 5.1 and 7; Get cmdlets only read, New/Set/Remove need admin. On the office PC everything ran only on the loopback interface or global settings.

210.1 Why is it used?

  • Replaces ipconfig, route print and arp -a with objects you can filter (Where-Object) and select (Select-Object).
  • Answer "which route and source IP will Windows use?" with Find-NetRoute.
  • Same commands work on remote servers with -CimSession.
  • Scriptable checks: default gateway, interface metrics, MTU, DHCP state.

210.2 How it works: one packet, one cmdlet per step

Sending a packet to 8.8.8.8
  1. 1.Find-NetRoute: Windows picks the route 0.0.0.0/0

  2. 2.Get-NetIPAddress: source IP 192.168.1.10/24

  3. 3.Get-NetRoute: default route next hop 192.168.1.1

  4. 4.Get-NetNeighbor: MAC address of the gateway 192.168.1.1

  5. 5.Packet goes through the router to the internet (8.8.8.8)

210.3 Common parameters

PowerShell
$j = Get-NetPrefixPolicy -Precedence 50 -AsJob$null = Wait-Job $j -Timeout 20Receive-Job $jGet-NetIPv4Protocol -ThrottleLimit 2 | Format-List DefaultHopLimit
Output
$ $j = Get-NetPrefixPolicy -Precedence 50 -AsJobId State   HasMoreData Command-- -----   ----------- ------- 1 Running        True Get-NetPrefixPolicy -Precedence 50 -AsJob$ Receive-Job $jPrefix  Precedence Label------  ---------- -----::1/128         50     0$ Get-NetIPv4Protocol -ThrottleLimit 2 | Format-List DefaultHopLimitDefaultHopLimit : 128
ParameterMeaning
-AsJobRun as a background job; the prompt is free immediately
-CimSessionRun on a remote computer / session
-ThrottleLimitMax parallel operations
-WhatIf / -ConfirmSafety switches for New/Set cmdlets

210.4 Get-NetIPAddress

PowerShell
$lo = 'Loopback Pseudo-Interface 1'Get-NetIPAddress -InterfaceAlias $lo |  Format-Table IPAddress, PrefixLength, AddressFamily, PrefixOrigin, AddressStateGet-NetIPAddress -InterfaceAlias $lo -AddressFamily IPv4 |  Format-List IPAddress, InterfaceIndex, Type, SuffixOrigin, ValidLifetime, SkipAsSource
Output
IPAddress PrefixLength AddressFamily PrefixOrigin AddressState--------- ------------ ------------- ------------ ------------::1                128          IPv6    WellKnown    Preferred127.0.0.1            8          IPv4    WellKnown    Preferred IPAddress      : 127.0.0.1InterfaceIndex : 1Type           : UnicastSuffixOrigin   : WellKnownValidLifetime  : 10675199.02:48:05.4775807SkipAsSource   : False
  • One object per IP address; loopback has 127.0.0.1/8 and ::1, both WellKnown and Preferred.
  • ValidLifetime is huge because a loopback address never expires.
  • PrefixOrigin/SuffixOrigin show Manual, Dhcp, RouterAdvertisement, WellKnown...; AddressState shows DAD state (Preferred, Tentative...).
  • SkipAsSource $true = never used as the source IP of outgoing traffic.

210.5 Get-NetIPConfiguration

PowerShell
Get-NetIPConfiguration -InterfaceAlias $lo(Get-Command Get-NetIPConfiguration).ParameterSets.NameGet-NetIPConfiguration -InterfaceAlias "Ethernet" -DetailedGet-NetIPConfiguration -All
Output
$ Get-NetIPConfiguration -InterfaceAlias $lo(no output)$ (Get-Command Get-NetIPConfiguration).ParameterSets.NameAliasIndexAll
  • ipconfig-style summary: adapter, IPv4 address, gateway, DNS servers.
  • No output for loopback: without -All it shows only connected, non-virtual interfaces.
  • -Detailed adds MTU, DHCP status, network profile and computer name.

210.6 Get-NetIPInterface

PowerShell
Get-NetIPInterface -InterfaceAlias $lo |  Format-Table ifIndex, AddressFamily, NlMtu, InterfaceMetric, Dhcp, ConnectionStateGet-NetIPInterface -InterfaceAlias $lo -AddressFamily IPv4 |  Format-List Forwarding, WeakHostSend, WeakHostReceive, RouterDiscovery, AutomaticMetric, NeighborDiscoverySupported
Output
ifIndex AddressFamily      NlMtu InterfaceMetric     Dhcp ConnectionState------- -------------      ----- ---------------     ---- ---------------      1          IPv6 4294967295              75 Disabled       Connected      1          IPv4 4294967295              75 Disabled       Connected Forwarding                 : DisabledWeakHostSend               : DisabledWeakHostReceive            : DisabledRouterDiscovery            : ControlledByDHCPAutomaticMetric            : EnabledNeighborDiscoverySupported : No
  • Each adapter has a separate IPv4 and IPv6 row.
  • Windows adds route metric + interface metric to choose a route; loopback InterfaceMetric is 75.
  • NlMtu is huge on loopback (no real wire); Forwarding Disabled = the PC does not route packets.
  • WeakHostSend/Receive matter on multi-homed servers; ReachableTimeMs, RetransmitTimeMs, DAD timers are for neighbor discovery.

210.7 Get-NetRoute and Find-NetRoute

PowerShell
Get-NetRoute -DestinationPrefix 127.0.0.0/8, '::1/128' |  Format-Table ifIndex, DestinationPrefix, NextHop, RouteMetric, ProtocolGet-NetRoute -DestinationPrefix "0.0.0.0/0" | Select-Object -ExpandProperty "NextHop"Find-NetRoute -RemoteIPAddress 127.0.0.1 |  Format-List InterfaceAlias, IPAddress, DestinationPrefix, NextHop, RouteMetric
Output
$ Get-NetRoute -DestinationPrefix 127.0.0.0/8, '::1/128' | Format-Table ...ifIndex DestinationPrefix NextHop RouteMetric Protocol------- ----------------- ------- ----------- --------      1 127.0.0.0/8       0.0.0.0         256    Local      1 ::1/128           ::              256    Local$ Find-NetRoute -RemoteIPAddress 127.0.0.1 | Format-List ...InterfaceAlias : Loopback Pseudo-Interface 1IPAddress      : 127.0.0.1 InterfaceAlias    : Loopback Pseudo-Interface 1DestinationPrefix : 127.0.0.1/32NextHop           : 0.0.0.0RouteMetric       : 256
Output
PS C:\>Find-NetRoute -RemoteIPAddress "10.79.197.200"IPAddress         : 172.31.234.140InterfaceAlias    : EthernetPrefixLength      : 21PrefixOrigin      : Dhcp...DestinationPrefix  : 0.0.0.0/0NextHop            : 172.31.232.1Protocol           : NetMgmt
  • NextHop 0.0.0.0 / :: = on-link route; Protocol Local = created by Windows; RouteMetric 256.
  • Get-NetRoute -DestinationPrefix 0.0.0.0/0 | Select-Object -ExpandProperty NextHop = only the default gateway.
  • Find-NetRoute returns two objects: the chosen source IP and the chosen route.
  • Filters: -NextHop, -Protocol (Local, NetMgmt, Dhcp, Ospf, Bgp...), -AddressFamily, -InterfaceIndex.

210.8 Compartments and global IPv4/IPv6 settings

PowerShell
Get-NetCompartment | Format-List CompartmentId, CompartmentDescription, CompartmentTypeGet-NetIPv4Protocol | Format-List DefaultHopLimit, NeighborCacheLimit, MinimumMtu, IcmpRedirects, SourceRoutingBehavior, DeadGatewayDetection, IGMPVersion, RandomizeIdentifiersGet-NetIPv6Protocol | Format-List DefaultHopLimit, UseTemporaryAddresses, MaxValidLifetime, MaxPreferredLifetime, RegenerateTime, MldVersion, RandomizeIdentifiers
Output
CompartmentId          : 1CompartmentDescription : Default CompartmentCompartmentType        : Native DefaultHopLimit       : 128NeighborCacheLimit    : 256MinimumMtu            : 576IcmpRedirects         : EnabledSourceRoutingBehavior : DontForwardDeadGatewayDetection  : EnabledIGMPVersion           : Version3RandomizeIdentifiers  : Enabled DefaultHopLimit       : 128UseTemporaryAddresses : EnabledMaxValidLifetime      : 7.00:00:00MaxPreferredLifetime  : 1.00:00:00RegenerateTime        : 00:00:05MldVersion            : Version2RandomizeIdentifiers  : Enabled
  • A normal PC has one Default Compartment (ID 1); containers/VPNs may add more: try -IncludeAllCompartments if a route is missing.
  • DefaultHopLimit 128 = every IPv4 packet leaves Windows with TTL 128.
  • SourceRoutingBehavior DontForward = source-routed packets are not forwarded.
  • UseTemporaryAddresses Enabled = random privacy IPv6 addresses (valid max 7 days, preferred 1 day).
  • IPv6 uses MLD instead of IGMP for multicast groups.

210.9 Neighbors, offload and prefix policy

PowerShell
Get-NetNeighbor -InterfaceAlias $lo -AddressFamily IPv4 |  Format-Table IPAddress, LinkLayerAddress, StateGet-NetNeighbor -State Reachable | Get-NetAdapterGet-NetOffloadGlobalSettingGet-NetPrefixPolicy | Format-Table Prefix, Precedence, Label
Output
IPAddress       LinkLayerAddress     State---------       ----------------     -----239.255.255.250                  Permanent224.0.0.251                      Permanent224.0.0.22                       Permanent ReceiveSideScaling           : EnabledReceiveSegmentCoalescing     : EnabledChimney                      : DisabledTaskOffload                  : EnabledNetworkDirect                : EnabledNetworkDirectAcrossIPSubnets : BlockedPacketCoalescingFilter       : Enabled Prefix        Precedence Label------        ---------- -----3ffe::/16              1    12fec0::/10              1    11::/96                  1     3fc00::/7               3    132001::/32              5     52002::/16             30     2::ffff:0:0/96         35     4::/0                  40     1::1/128               50     0
  • Get-NetNeighbor = ARP / IPv6 neighbor cache as objects; loopback shows only Permanent multicast entries with no MAC.
  • RSS spreads receive traffic across CPU cores; RSC joins small segments; TCP Chimney is old and disabled.
  • Prefix policy (RFC 6724): higher Precedence wins, so ::/0 (40) beats ::ffff:0:0/96 (35): IPv6 is tried before IPv4.

210.10 Comparison: classic command vs NetTCPIP cmdlet

TaskClassicPowerShell
IP addressesipconfigGet-NetIPAddress
Summary per adapteripconfig /allGet-NetIPConfiguration [-Detailed]
Routing tableroute printGet-NetRoute
Which route is used(none)Find-NetRoute -RemoteIPAddress
ARP cachearp -aGet-NetNeighbor
Interface metric / MTUnetsh interface ipv4 show interfacesGet-NetIPInterface

210.11 Common mistakes

  • Thinking a working loopback means the network is fine: loopback packets never leave the PC; check Find-NetRoute and the gateway in Get-NetNeighbor.
  • Expecting Get-NetIPConfiguration to show loopback or disconnected adapters without -All.
  • Forgetting the interface metric when two adapters have a default route.
  • Running Set/New/Remove cmdlets without admin (or without -WhatIf first).

210.12 Interview tips

  • IP = Get-NetIPAddress, routes = Get-NetRoute, ARP = Get-NetNeighbor, summary = Get-NetIPConfiguration.
  • Only the default gateway: Get-NetRoute -DestinationPrefix 0.0.0.0/0 | Select-Object -ExpandProperty NextHop.
  • Find-NetRoute shows the source IP and route Windows will use for any destination.
  • All return objects: filter with Where-Object, run remotely with -CimSession.