Solved

Set WiFI Metric with Powershell

Posted on 2014-02-24
8
1,775 Views
Last Modified: 2014-02-24
I am attempting to make a powershell script that would set the metric for the WiFi IPv4 and v6 with powershell.  I have to use DHCP.  Please assist and if you would explain the script it would be nice.  I am attempting to learn powershell.
0
Comment
Question by:Jeremy Tyre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 9

Assisted Solution

by:Sean
Sean earned 500 total points
ID: 39882683
This is for windows 8, I don't know if it will work on 7 or not

to get your interfaces:
Get-NetIPInterface

to set the interface metric:
Set-NetIPInterface -InterfaceAlias Wi-Fi -AddressFamily IPv4 -InterfaceMetric 1

The InterfaceAlias may be different.
0
 
LVL 3

Author Comment

by:Jeremy Tyre
ID: 39882713
NetIPInterface does not appear to be in Windows 7 powershell, but it does work for 8!  That solves half the problem and thank you for the explinations
0
 
LVL 9

Expert Comment

by:Sean
ID: 39882720
Windows 7:
Get-WmiObject Win32_NetworkAdapterConfiguration -filter "ipenabled = 'true'"

Note index number

$nic = Get-WmiObject Win32_NetworkAdapterConfiguration -filter "index=22"

$nic.SetGateways($gateway,1)
0
Is your NGFW recommended by NSS Labs?

Ours is! NSS Labs Next Generation Firewall Test gives the WatchGuard Firebox M4600 a "Recommended" rating! Curious where your NGFW landed on the  Security Value Map? See the map and download the full report today!

 
LVL 3

Author Comment

by:Jeremy Tyre
ID: 39882834
Works up until the $gateway:

You cannot call a method on a null-valued expression.
At line:1 char:17
+ $nic.SetGateways <<<< ($gateway,9999)
    + CategoryInfo          : InvalidOperation: (SetGateways:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Is there anyways of doing this without setting the gateway?
0
 
LVL 9

Expert Comment

by:Sean
ID: 39883080
Sorry about that i don't know where i was going with that...try this...

netsh interface ipv4 show addresses
note the name
netsh interface ipv4 set interface "Wireless Network Connection" metric=1
0
 
LVL 3

Author Comment

by:Jeremy Tyre
ID: 39883104
Lets add another level of difficulty.  :)  I need to do this with computer names that end in -T and -L
0
 
LVL 9

Accepted Solution

by:
Sean earned 500 total points
ID: 39883153
$hostname = gc env:computername

if($hostname.endswith("=T") -or $hostname.endswith("=L"))
{
      netsh interface ipv4 set interface "Wireless Network Connection" metric=1
}
0
 
LVL 3

Author Closing Comment

by:Jeremy Tyre
ID: 39883176
Very helpful and helped me work through multiple issues.  Zindell even explained the answer and helped me learn more about Powershell
0

Featured Post

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

688 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