Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1965
  • Last Modified:

Set WiFI Metric with Powershell

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
Jeremy Tyre
Asked:
Jeremy Tyre
  • 4
  • 4
2 Solutions
 
SeanSystem EngineerCommented:
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
 
Jeremy TyreAuthor Commented:
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
 
SeanSystem EngineerCommented:
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
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
Jeremy TyreAuthor Commented:
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
 
SeanSystem EngineerCommented:
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
 
Jeremy TyreAuthor Commented:
Lets add another level of difficulty.  :)  I need to do this with computer names that end in -T and -L
0
 
SeanSystem EngineerCommented:
$hostname = gc env:computername

if($hostname.endswith("=T") -or $hostname.endswith("=L"))
{
      netsh interface ipv4 set interface "Wireless Network Connection" metric=1
}
0
 
Jeremy TyreAuthor Commented:
Very helpful and helped me work through multiple issues.  Zindell even explained the answer and helped me learn more about Powershell
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now