Skip to content

Instantly share code, notes, and snippets.

@toyg
Created November 2, 2017 12:06
Show Gist options
  • Save toyg/f0a836ce0309009592c031aadd7a36f3 to your computer and use it in GitHub Desktop.
Save toyg/f0a836ce0309009592c031aadd7a36f3 to your computer and use it in GitHub Desktop.
Manually set Windows "Metrics" values for network cards. When a server has multiple cards, you are often forced to disable Windows' automatic "metrics", to make sure EPM traffic goes on the right interface.
# To use this script, rename LAN, BACKUP etc to match relevant network card names
# in your environment (you can add or remove lines as well),
# and set values to match your metric preference (1 is the preferred card).
# All cards not mentioned here will be set to 100.
$cards = @{} # don't touch this line
$cards.LAN = 1
$cards.BACKUP = 99
$cards.MGMT = 98
# Don't change anything below, just copypaste.
$protocols = 'IPv4','IPv6'
$all_cards = Get-NetIPInterface
foreach($card in $all_cards){
    if($cards.$card){
        foreach($protocol in $protocols){
            Set-NetIPInterface -InterfaceAlias $card -AddressFamily $protocol -InterfaceMetric $cards.$card ;
        }
    } else {
        Set-NetIPInterface -InterfaceAlias $card -AddressFamily $protocol -InterfaceMetric 100 ;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment