Solved

Set WiFI Metric with Powershell

Posted on 2014-02-24
8
1,573 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

776 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