Change the priority of traffic to wired instead of the wireless connection?

On Windows 7 clients I have to change the metric of the wired network connection to a lower metric than the wireless so traffic is prioritized over the wired connection.  Is there a way to do this through a script using powershell?

To do this manually i -> Open network and sharing centre -> click the network wired connection -> select properties -> IPv4 -> advanced -> disable automatic metric -> enter a interface of 10 and then repeat for the wireless network adapter but enter a higher metric of say 20.

I've found these instruction on how to get the metric through netstat but not how to change the metric.   Thank.

 

http://www.howtogeek.com/howto/27994/how-to-change-the-priority-of-wiredwireless-network-cards-in-windows/
resolver1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

edster9999Commented:
You can change the metric but you will still have some issues further down the road.
Some apps or printers will have an issue with 2x different IPs on the same machine.
A better idea is to disable the Wireless card when I live cable is plugged in.
There is normally a patch to do this from the card maker (ie Intel).

0
Darius GhassemCommented:
You can use netsh interface ipv4 set interface "Local Area Connection" metric=

Or use this script

==== snip - Start of script code Set_Wireless_NIC_IPMetric.vbs script ====
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

regValueDataMetric = "35"

Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter Where NetConnectionID = 'Wireless Network Connection'")

For Each objItem in colItems
strMACAddress = objItem.MACAddress
Wscript.Echo "MACAddress: " & strMACAddress
Next

Set colNetCard = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetCard in colNetCard
If objNetCard.MACAddress = strMACAddress Then
For Each strIPAddress in objNetCard.IPAddress
Wscript.Echo "Description: " & objNetCard.Description
Wscript.Echo "IP Address: " & strIPAddress
Wscript.Echo "IPConnectionMetric: " & objNetCard.IPConnectionMetric
objNetCard.SetIPConnectionMetric(regValueDataMetric)
Next
End If
Next
==== snip - End of VBS script ====

http://support.microsoft.com/kb/894564
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
resolver1Author Commented:
I can disable the wireless card if its just one but I don't want to do this for 40 machines.  I'll give the script a go.  Can you see any issues with putting this in a group policy to catch all our windows 7 machines?
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Darius GhassemCommented:
First do the script on a couple of stations then you can deploy through GPO
0
resolver1Author Commented:
The script doesn't appear to work. I've added a couple of lines to the script to check the  objNetCard.IPConnectionMetric settings after the script is suppose to change the value but it doesn't change it.  Any ideas why?

The setting displayed from "script.Echo "IPConnectionMetric: " & objNetCard.IPConnectionMetric"
 doesnt correspond to "netstat -rn" screen.

I'm running the script as administrator and the script has been run by right clicking and run as administrator.  Any ideas ?

 
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

regValueDataMetric = "35"

Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter Where NetConnectionID = 'Wireless Network Connection'")

For Each objItem in colItems
	strMACAddress = objItem.MACAddress
	Wscript.Echo "MACAddress: " & strMACAddress
Next

Set colNetCard = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetCard in colNetCard
	If objNetCard.MACAddress = strMACAddress Then
		For Each strIPAddress in objNetCard.IPAddress
			Wscript.Echo "Description: " & objNetCard.Description
			Wscript.Echo "IP Address: " & strIPAddress
			Wscript.Echo "IPConnectionMetric: " & objNetCard.IPConnectionMetric
			objNetCard.SetIPConnectionMetric(regValueDataMetric)
			Wscript.Echo "next is the changed metric" 
			Wscript.Echo "IPConnectionMetric: " & objNetCard.IPConnectionMetric
		Next
	End If
Next

Open in new window



 
===========================================================================
Interface List
 16...00 ff f0 29 36 b7 ......TAP-Win32 Adapter V9
 12...00 27 13 75 3d 84 ......Bluetooth Device (Personal Area Network)
 11...00 26 c6 80 2d 02 ......Intel(R) WiFi Link 5100 AGN
 10...d8 d3 85 03 e7 b3 ......Marvell Yukon 88E8042 PCI-E Fast Ethernet Cont
 14...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
 15...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
  1...........................Software Loopback Interface 1
 22...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #8
 24...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #9
 19...00 00 00 00 00 00 00 e0 Teredo Tunneling Pseudo-Interface
 25...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #6
 20...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #5
 18...00 00 00 00 00 00 00 e0 Microsoft 6to4 Adapter #127
 21...00 00 00 00 00 00 00 e0 Microsoft 6to4 Adapter #142
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0    192.34.98.254    192.34.98.148    100
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
      192.34.98.0    255.255.255.0         On-link     192.34.98.148    356
    192.34.98.148  255.255.255.255         On-link     192.34.98.148    356
    192.34.98.255  255.255.255.255         On-link     192.34.98.148    356
    192.168.150.0    255.255.255.0         On-link     192.168.150.1    276
    192.168.150.1  255.255.255.255         On-link     192.168.150.1    276
  192.168.150.255  255.255.255.255         On-link     192.168.150.1    276
    192.168.198.0    255.255.255.0         On-link     192.168.198.1    276
    192.168.198.1  255.255.255.255         On-link     192.168.198.1    276
  192.168.198.255  255.255.255.255         On-link     192.168.198.1    276
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    306
        224.0.0.0        240.0.0.0         On-link     192.168.198.1    276
        224.0.0.0        240.0.0.0         On-link     192.168.150.1    276
        224.0.0.0        240.0.0.0         On-link     192.34.98.148    356
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    306
  255.255.255.255  255.255.255.255         On-link     192.168.198.1    276
  255.255.255.255  255.255.255.255         On-link     192.168.150.1    276
  255.255.255.255  255.255.255.255         On-link     192.34.98.148    356
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
 21   1125 ::/0                     2002:c058:6301::c058:6301
  1    306 ::1/128                  On-link
 21   1025 2002::/16                On-link
 21    281 2002:c022:6294::c022:6294/128
                                    On-link
 14    276 fe80::/64                On-link
 15    276 fe80::/64                On-link
 11    276 fe80::/64                On-link
 15    276 fe80::314e:2031:96ed:ef1d/128
                                    On-link
 14    276 fe80::79fa:3030:6c3e:6b25/128
                                    On-link
 11    276 fe80::7ca2:6e30:283b:cc10/128
                                    On-link
  1    306 ff00::/8                 On-link
 14    276 ff00::/8                 On-link
 15    276 ff00::/8                 On-link
 11    276 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

Open in new window

0
Maen Abu-TabanjehNetwork Administrator, Network ConsultantCommented:
0
Maen Abu-TabanjehNetwork Administrator, Network ConsultantCommented:
@modus_in_rebus:
i have resend the original link , i  have fight with someone  here because posting links , we don't what to do with people...just this why i copied script here.
0
resolver1Author Commented:
Sorry for the delay.  I'll get back to you with the results of script
0
Maen Abu-TabanjehNetwork Administrator, Network ConsultantCommented:
@modus_in_rebus:
ok thak you i got the message :)
0
resolver1Author Commented:
I've changed BIOS settings on some of the machines to disable the wireless when the wired is plugged in.  The machines without the option to disable the BIOS have the script run against them.

Thnaks for your time guys
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.