Configuring WLAN NIC Parameters with PowerShell
This post is heavily based on Microsoft’s TechNet Blog entry titled Using PowerShell for NIC Configuration Tasks, but has been tailored around Wireless LAN (WLAN) Network Interface Controller (NIC) Parameters.
- Introduction
- Requirements
- Finding and naming your NIC
- Viewing and Setting Advanced NIC Parameters
- Determining Valid Parameter Values
- Resetting a Parameter to the Default Value
- Batching Commands
- Determining the NIC Driver
- Using Enter-PSSession to change a remote machine’s WLAN NIC parameters
- Appendix: Commands
- Appendix: Changelog
Introduction
Since Windows 8 and Windows Server 2012, Windows PowerShell makes it easy to set and check the network parameters that previously had to be set using the Network Control Panel. While you can still use the Network Control Panel to change specific network parameters, PowerShell makes it possible to automate the process.
Windows PowerShell is a Windows command-line shell designed especially for system administrators. Windows PowerShell includes an interactive prompt and a scripting environment that can be used independently or in combination.
There are several PowerShell CmdLet’s that can be used to automate the configuration management of the WLAN NICs for these clients.
cmdlet (pronounced command-let) is a single-feature command that manipulates objects in Windows PowerShell. You can recognize cmdlets by their name format – a verb and noun separated by a dash (-), such as Get-Help, Get-Process, and Start-Service.
In this post, I will show how to leverage PowerShell to change the Roaming Aggressiveness, Transmit Power, and Preferred Band WLAN NIC settings:
- getting and setting NIC parameter settings
- determining valid NIC parameters
- resetting parameters to Factory Default Values
- using the -NoRestart flag to ‘batch’ changes
- determining the NIC driver version
There are also other specific parameters (and you can change wired NIC settings) that can be adjusted using these methods, so working through understanding the fundamentals will be helpful.
Depending on your environment, you may need an admin account and use an elevated PowerShell prompt to perform these tasks. For example, on my machine the commands that modify settings are restricted to administrative accounts only.
Requirements
- PowerShell version 6.0 or newer
- Windows 8 or newer
- Windows Server 2012 or newer
Finding and naming your NIC
If you have multiple NICs, remembering which is which can be difficult. Consistent Device Naming (CDN) was added in Windows 8 and Windows Server 2012 and makes it easier to determine which physical network interface is which.
With PowerShell, you can give your NICs descriptive names which you can use for subsequent configuration tasks. This would be particularly useful if you have multiple WLAN NICs. This is not covered in this post.
Using the Get-NetAdapter
CmdLet we will get a list of all the NICs on the current local machine (abbreviated to fit on screen better):
Depending on how many NICs you use, you may be able to ignore the following and the CDN feature mentioned above. However, if you have multiple WLAN NICs, you would probably see something like this:
In this case, it might make sense to rename the NICs to something easier to understand. So, let’s cover how to rename the NIC to something more clear.
PS C:\windows\system32> Rename-NetAdapter -Name "Wi-Fi" 'Internal WLAN NIC'
Run the Get-NetAdapter
CmdLet again to see the updated name.
PS C:\windows\system32> Get-NetAdapter
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
...
Internal WLAN NIC Intel(R) Dual Band Wireless-AC 8265 8 Up 28-C6-3F-XX-XX-AF 300 Mbps
...
Viewing and Setting Advanced NIC Parameters
As a practical example, I will first look at some NIC parameters, and then show how to change them with PowerShell. To examine the WLAN NIC parameters for my Wi-Fi
NIC identified earlier we can use the following. And to demonstrate wildcards, I’m going to abbreviate the NIC named Wi-Fi
as W*i
. PowerShell will expand the wildcard.
a wildcard is a symbol used to replace or represent one or more characters.
Consider where you have a particular Service Set Identifier (SSID) deployed on both 2.4 GHz and 5 GHz radios (11 b/g/n && 11 a/n/ac). There will be a BSSID specific to each radio for the same SSID. Let’s change the Preferred Band to 5 GHz. Changing the preferred band to 5 GHz will tell the client driver to prefer connecting to a 5 GHz BSSID rather than the 2.4 GHz BSSID. By default the client WLAN driver will likely prefer connecting to the 2.4 GHz BSSID. This may not be ideal.
To set the NIC to prefer 5 GHz:
Set-NetAdapterAdvancedProperty W*i -DisplayName "Preferred Band" -DisplayValue "3. Prefer 5.2GHz band"
To verify it changed you can use this command:
Get-NetAdapterAdvancedProperty W*i -DisplayName "Preferred Band"
This section illustrates by using the -DisplayName
and -DisplayValue
switches, we can identify the names and advanced properties for a NIC that we want to set (change) using PowerShell.
Determining Valid Parameter Values
Different kinds of NICs (LAN vs WLAN) will have different parameter settings. You can use PowerShell to determine which values are valid for a particular parameter on a particular NIC. These values are provided by the NIC Driver and will reflect the specific capabilities of the NIC.
Let’s look at all the parameters and their possible values for my Wi-Fi
NIC and format the display as a table using a format table (ft
).
This may be more information than we’re looking for, so let’s filter the output and just look at the possible values for Roaming Aggressiveness
:
PS C:\windows\system32> Get-NetAdapterAdvancedProperty W*i -DisplayName Roam* | ft DisplayName, DisplayValue, ValidDisplayValues
DisplayName DisplayValue ValidDisplayValues
----------- ------------ ------------------
Roaming Aggressiveness 3. Medium {1. Lowest, 2. Medium-low, 3. Medium, 4. Medium-High...}
Here we see the only valid values for Roaming Aggressiveness
are:
{1. Lowest, 2. Medium-low, 3. Medium, 4. Medium-High...}
This gives us a list of valid values that we can set Roaming Aggressiveness
as. To change the value to 4. Medium-High
we can use this command:
Set-NetAdapterAdvancedProperty W*i -DisplayName "Roaming Aggressiveness" -DisplayValue "4. Medium-High"
Resetting a Parameter to the Default Value
If you want to reset a parameter back to the default value, you can use the Reset-NetAdapterAdvancedProperty
CmdLet. Here’s how to set Transmit Power
back to the factory default:
Reset-NetAdapterAdvancedProperty W*i -DisplayName "Transmit Power"
If you’d like to reset all of the parameters back to their default values, you can use a wild card:
Reset-NetAdapterAdvancedProperty W*i -DisplayName *
Batching Commands
When you change a NIC parameter, the NIC driver needs to be restarted in order for the change to be applied. If you normally use the control panel, you may have noticed that when you apply changes, the affected network interface goes down (bounces) briefly while the driver is restarted.
Each time you change a parameter with PowerShell, the NIC will bounce while the driver restarts. However, PowerShell has a feature that will allow batching multiple changes into a single operation. This will reduce the number of times the NIC will bounce during configuration, and will speed up the configuration when changing multiple parameters at the same time.
This is especially noticeable if you are making changes through a remote terminal session and the remote NIC used for the session resets. The session will be interrupted if the end device is using the same NIC for connectivity that you are making changes to.
If you are making multiple changes, PowerShell allows you to batch multiple changes and have them all applied with a single driver restart by using the -NoRestart
flag.
For example, suppose I have the following three WLAN parameters I want to change. I can append -NoRestart
to all of the following commands except the last.
The NIC will be restarted when the last CmdLet runs, and will apply all the previous settings at one time. The NIC will only bounce once.
If you experience issues with the NIC, you could explicitly restart the NIC by invoking: Restart-NetAdapter (NIC Name)
or in this example Restart-NetAdapter Wi-Fi
.
You may also be familiar with the Enable-NetAdapter
and Disable-NetAdapter
CmdLet’s that let you enable and disable your network respectively. However, you should consider using Restart-NetAdapter
described above as a safer option with remote connections. This is because Disable-NetAdapter
is asynchronous and will return immediately to the script before the adapter is fully disabled. When the script calls Enable-NetAdapter
, it will fail because the adapter isn’t fully disabled yet. Restart-NetAdapter
combines these into a single operation. More here.
Determining the NIC Driver
Determining the NIC driver version is another common task. This is easy to do with PowerShell using the Get-NetAdapter
properties. In this example, I’m using a wildcard to display, in a list format, all of the driver information:
Using Enter-PSSession to change a remote machine’s WLAN NIC parameters
The Enter-PSSession CmdLet will start an interactive PowerShell session with a remote computer either via Kerberos or NTLM authentication. Note that this requires at least PowerShell version 6.
Once connected, you can issue commands just like you were on your local machine. However, it’s important to note that once you run a command that restarts the NIC driver, it will cause a break in connectivity to the remote device, and the remote device (if it’s using the NIC for connectivity). This is usually just a few moments, but could be up to a minute or two. This is because the NIC bounces while the driver is restarted.
Here’s an example connecting to a remote machine using it’s computer name:
Here’s an example connecting to a remote machine via IP:
Because Kerberos authentication does not support IP addresses, NTLM auth is used by default when you specify an IP address. This means you must either use HTTPS transport or add the IP address of the remote machine to the TrustedHosts list on the local machine, and also pass in a PSCredential object into the Credential parameter in all remote commands. Create a PSCredential object with the Get-Credential
CmdLet. For troubleshooting see this technet post.
Appendix: Commands
Get Transmit Power
value example output:
Get:
Get-NetAdapter
Get-NetAdapterAdvancedProperty Wi-Fi
Get-NetAdapterAdvancedProperty Wi-Fi | ft DisplayName, DisplayValue, ValidDisplayValues
Get-NetAdapterAdvancedProperty Wi-Fi -DisplayName *Band* | ft DisplayName, DisplayValue, ValidDisplayValues
Get-NetAdapterAdvancedProperty Wi-Fi -DisplayName *Roam* | ft DisplayName, DisplayValue, ValidDisplayValues
Set:
Set-NetAdapterAdvancedProperty W*i -DisplayName "Preferred Band" -DisplayValue "3. Prefer 5.2GHz band"
Set-NetAdapterAdvancedProperty W*i -DisplayName "Roaming Aggressiveness" -DisplayValue "3. Medium"
Batching example:
Set-NetAdapterAdvancedProperty Wi-Fi -DisplayName Roaming* -DisplayValue '3. Medium' -NoRestart
Set-NetAdapterAdvancedProperty Wi-Fi -DisplayName Transmit* -DisplayValue '4. Medium-High' -NoRestart
Set-NetAdapterAdvancedProperty Wi-Fi -DisplayName Preferred* -DisplayValue "3. Prefer 5.2GHz band"
Note: remember that the NIC bounces due to driver reset after last command.
Misc:
Reset-NetAdapterAdvancedProperty W*i -DisplayName "Transmit Power"
Reset-NetAdapterAdvancedProperty W*i -DisplayName *
Enter-PSSession
Enter-PSSession -ComputerName FOOBARPC
Links:
Appendix: Changelog
- 20180823: original post
- 20180827 & 20180909: fixed typos, added clarification, updated remote machine section