Get Gateway IP
Last Modified: February 25, 2024 18:18 CEST

Get-GatewayIp #

SYNOPSIS #

Gets the IP address of the local gateway router

SYNTAX #

Get-GatewayIp [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION #

This function retrieves the IP address of the local gateway router by using the Get-NetRoute cmdlet to retrieve the routing table information for the IPv4 address family. It then filters the routing table to only include the default route, represented by the DestinationPrefix of “0.0.0.0/0”. Finally, it selects the NextHop IP address of the default route, which represents the IP address of the local gateway router.

EXAMPLES #

Example 1:Retrieves the IP address of the gateway #

PS C:\> Get-GatewayIp
# Output

192.168.178.1

Retrieves the IP address of the gateway

PARAMETERS #

CommonParameters #

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS #

None #

OUTPUTS #

System.Object #

NOTES #