[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Powershell: Change metric on specific adapter

Posted on 2016-11-16
6
Medium Priority
?
359 Views
1 Endorsement
Last Modified: 2016-11-20
Recently Windows has taken away the adapter binding setting/GUI under network adapters -advanced -advanced settings (see image), they stated that nothing uses the adapter binding other than DNS, well I still need it for DNS, I’ve looked at a few PowerShell scripts that changes the Metric on an adapter to route DNS requests to one adapter first. These scripts work great, however the issue I have is I have no way to find the adapter automatically. I have to query each machine in order to place the metric on a particular adapter. I run the Get-NetAdapter On the target machine and the only thing in common on all the machines is the InterfaceDescription which was set when this adapter was installed. So the question I have is can I edit using PowerShell an adapters setting based upon the InterfaceDescription.
bring.PNG
So I have
Get-NetAdapter | where {$_.InterfaceDescription -eq “NeoRouter Virtual Network Interface”}
 But id like to cache the mac address of the neo router to  change its metric?
get-NetIPInterface doesn’t list mac address nor InterfaceDescription, so is there a way to match up get-NetIPInterface with Get-NetAdapter I tried using Get-WmiObject -Class Win32_NetworkAdapter.
I saw this script that does something similar
https://gallery.technet.microsoft.com/scriptcenter/Change-wired-network-db174767


Thanks in advance
1
Comment
Question by:Joe Danyi
  • 3
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 41891070
You can link them with the Interface index:
$NetIPInterface = Get-NetIPInterface -InterfaceIndex (Get-NetAdapter -InterfaceDescription 'NeoRouter Virtual Network Interface').ifIndex

Open in new window

2
 
LVL 1

Author Comment

by:Joe Danyi
ID: 41894883
Worked perfectly i did need to narrow down to just the IPV4 So i added
$NetIPInterface = Get-NetIPInterface -InterfaceIndex (Get-NetAdapter -InterfaceDescription 'NeoRouter Virtual Network Interface').ifIndex
$NETIPInterface2 = $NetIPInterface| Where-Object {$_.DHCP -like "disabled"}
$NETIPInterface2 | Set-NetIPInterface -InterfaceMetric 100

dumb followup question for the metric is it lowest number goes first or highest number goes first.
IE im trying to route DNS traffic though my NEO router so will 100 mean it will go to that adapter first or will 1 make it go though that adapter first?
0
 
LVL 85

Expert Comment

by:oBdA
ID: 41894898
Metric is the cost; lower numbers cost less and will be preferred. And "100" or "1" by itself doesn't mean much - the lowest number decides.
1
 
LVL 1

Author Comment

by:Joe Danyi
ID: 41894922
just to be sure,

if i have 5 adapters and the metrics of the adatper asending from 1 - 5. that would mean the adapters with the lowest cost IE adatper 1 would go first then adatper 2 and so on. as apose to it decending where 5 goes first then 4.

and i thank you for your time.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 41894938
Yes.
1

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Loops Section Overview
Screencast - Getting to Know the Pipeline

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question