IP Default Gateways by cmdlet

Following my recent post on setting the default gateway by using the Win32_NetworkAdapterConfiguration CIM class here’s how you do it using the networking cmdlets

Discover your adapters


Check the default gateway for an adapter

Get-NetIPConfiguration -InterfaceIndex 12 | select InterfaceIndex, IPv4Address, IPv4DefaultGateway

Set the default gateway

New-NetRoute -InterfaceIndex 12  -DestinationPrefix ‘’ -NextHop ‘’

This isn’t as intuitive as using the CIM class

Check the setting

£> Get-NetIPConfiguration -InterfaceIndex 12

InterfaceAlias       : Ethernet
InterfaceIndex       : 12
InterfaceDescription : Microsoft Hyper-V Network Adapter
NetProfile.Name      : Manticore.org
IPv4Address          :
IPv6DefaultGateway   :
IPv4DefaultGateway   :
DNSServer            :

To remove the default gateway

Remove-NetRoute -InterfaceIndex 12 -NextHop ‘’ -Confirm:$false

If you leave off –Confirm you’ll be prompted to confirm the action on the active and persistent stores i.e. twice.

All of the above cmdlets are part of the NetTCPIP module available on Windows 8/Server 2012 and later.

This entry was posted in Networking, Powershell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s