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