Solved

Set WiFI Metric with Powershell

Posted on 2014-02-24
8
1,633 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
  • 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Need WiFi? Often, there are perfectly good networks that don't have WiFi capability - and there's a need to add it.  - Perhaps you have an Ethernet port into a network but no WiFi nearby. - Perhaps you have a powerline extender and no WiFi at the…
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

791 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