Changing IP Connection Metric

A question on the forums asked how the connection metrics could be set on a Windows system.

We need to start by identifying the network adapters using this function

function test-ipmetric {
Get-WmiObject -Class Win32_NetworkAdapter -Filter “AdapterType = ‘Ethernet 802.3′” |
foreach {
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “Index=$($_.DeviceId)” |
select Description, Index, IPEnabled, IPConnectionMetric
}
}

test-ipmetric | ft -a

Description                                                                                  Index IPEnabled IPConnect
                                                                                                                               ionMetric
———–                                                                                      —–     ———    ———
NVIDIA nForce 10/100/1000 Mbps Networking Controller              7         True        20
Atheros AR5007 802.11b/g WiFi Adapter                                      11        True        10
Microsoft Virtual WiFi Miniport Adapter                                          17        False

 

I get three adapters returned

The important ones are those that have IPEnabled set to True.

identify which is to have priority then run

function set-ipmetric {
param (
[int]$index,
[int]$metric
)
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “Index=$index” |
Invoke-WmiMethod -Name SetIPConnectionMetric -ArgumentList $metric
}

I used

set-ipmetric -index 7 -metric 200

set-ipmetric -index 11 -metric 100

This sets my wired to a higher metric than the wireless. If I wanted it the other way round

set-ipmetric -index 7 -metric 100

set-ipmetric -index 11 -metric 200

The system must be rebooted for the changes to take effect

Advertisements
This entry was posted in Networking, PowerShell and WMI. Bookmark the permalink.

2 Responses to Changing IP Connection Metric

  1. Kim says:

    Will this command always pull the same index values for lan(7) vs wlan(11)? Or will it be hardware dependent?
    I’d like to deploy something like this via GPO if possible.
    Thank you

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s