• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2064
  • 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 TyreDistributed Computer Systems AnalystAuthor 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
Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

 
Jeremy TyreDistributed Computer Systems AnalystAuthor 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 TyreDistributed Computer Systems AnalystAuthor 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 TyreDistributed Computer Systems AnalystAuthor 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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