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.

metal

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

Note

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.

Information

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):

PS C:\windows\system32> Get-NetAdapter

Name            InterfaceDescription     ifIndex Status       MacAddress             LinkSpeed
----            --------------------     ------- ------       ----------             ---------
Ethernet 3 ...  Cisco AnyConnect Secu...      20 Disabled     00-05-9A-XX-XX-00     298.5 Mbps
Wi-Fi      ...  Intel(R) Dual Band Wi...       8 Up           28-C6-3F-XX-XX-AF       300 Mbps
Ethernet 2 ...  Intel(R) Ethernet Con...      17 Disconnected A4-4C-C8-XX-XX-CA          0 bps
Ethernet 4 ...  Npcap Loopback Adapte...       2 Up           02-00-4C-XX-XX-50       1.2 Gbps
Npcap Loopb...  Npcap Loopback Adapte...      30 Up           02-00-4C-XX-XX-50       1.2 Gbps
Ethernet   ...  Realtek USB GbE Famil...       6 Disconnected A4-4C-C8-XX-XX-E4          0 bps

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:

PS C:\windows\system32> Get-NetAdapter

Name          InterfaceDescription       ifIndex Status       MacAddress             LinkSpeed
----          --------------------       ------- ------       ----------             ---------
Wi-Fi 14      802.11ac Wireless LAN C...     107 Disconnected CC-40-D0-XX-XX-85          0 bps
Ethernet 3    Cisco AnyConnect Secure...      20 Disabled     00-05-9A-XX-XX-00     298.5 Mbps
Wi-Fi 6       802.11ac Wireless LAN C...      25 Disconnected CC-40-D0-XX-XX-DD          0 bps
Wi-Fi         Intel(R) Dual Band Wire...       8 Up           28-C6-3F-XX-XX-AF       300 Mbps
Ethernet 2    Intel(R) Ethernet Conne...      17 Disconnected A4-4C-C8-XX-XX-CA          0 bps
Wi-Fi 10      Realtek 8812AU Wireless...      10 Not Present  40-A5-EF-XX-XX-BF          0 bps
Wi-Fi 9       Realtek 8812AU Wireless...      18 Not Present  40-A5-EF-XX-XX-F2          0 bps
Wi-Fi 8       Realtek 8812AU Wireless...      24 Disconnected 40-A5-EF-XX-XX-BF          0 bps
Wi-Fi 7       Realtek 8812AU Wireless...      29              40-A5-EF-XX-XX-E7          0 bps
Ethernet 4    Npcap Loopback Adapter ...       2 Up           02-00-4C-XX-XX-50       1.2 Gbps
Npcap Loo...  Npcap Loopback Adapter ...      30 Up           02-00-4C-XX-XX-50       1.2 Gbps
Wi-Fi 2       Realtek 8812AU Wireless...      15 Disconnected 40-A5-EF-XX-XX-F2          0 bps
Ethernet      Realtek USB GbE Family ...       6 Disconnected A4-4C-C8-XX-XX-E4          0 bps

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.

PS C:\windows\system32> Get-NetAdapterAdvancedProperty W*i

Name     DisplayName                    DisplayValue        RegistryKeyword RegistryValue
----     -----------                    ------------        --------------- -------------
Wi-Fi    Sleep on WoWLAN Disconnect     Disabled            *DeviceSleep... {0}
Wi-Fi    Packet Coalescing              Enabled             *PacketCoale... {1}
Wi-Fi    ARP offload for WoWLAN         Enabled             *PMARPOffload   {1}
Wi-Fi    NS offload for WoWLAN          Enabled             *PMNSOffload    {1}
Wi-Fi    GTK rekeying for WoWLAN        Enabled             *PMWiFiRekey... {1}
Wi-Fi    Wake on Magic Packet           Enabled             *WakeOnMagic... {1}
Wi-Fi    Wake on Pattern Match          Enabled             *WakeOnPattern  {1}
Wi-Fi    Bluetooth(R) AMP               Disabled            BT3HSMode       {0}
Wi-Fi    802.11n Channel Width for 2... Auto                ChannelWidth24  {1}
Wi-Fi    802.11n Channel Width for 5... Auto                ChannelWidth52  {1}
Wi-Fi    Mixed Mode Protection          RTS/CTS Enabled     CtsToItself     {0}
Wi-Fi    Fat Channel Intolerant         Disabled            FatChannelIn... {0}
Wi-Fi    Transmit Power                 5. Highest          IbssTxPower     {100}
Wi-Fi    HT Mode                        VHT Mode            IEEE11nMode     {2}
Wi-Fi    MIMO Power Save Mode           Auto SMPS           MIMOPowerSav... {0}
Wi-Fi    Roaming Aggressiveness         3. Medium           RoamAggressi... {2}
Wi-Fi    Preferred Band                 1. No Preference    RoamingPrefe... {0}
Wi-Fi    Throughput Booster             Disabled            ThroughputBo... {0}
Wi-Fi    U-APSD support                 Disabled            uAPSDSupport    {0}
Wi-Fi    Wireless Mode                  6. 802.11a/b/g      WirelessMode    {34}

Consider where you have a particular Service Set Identifier (SSID) deployed on both 2.4 GHz and 5 GHz radios (11 b/g/n & 11a/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).

PS C:\windows\system32> Get-NetAdapterAdvancedProperty W*i | ft DisplayName, DisplayValue, ValidDisplayValues

DisplayName                      DisplayValue          ValidDisplayValues
-----------                      ------------          ------------------
Sleep on WoWLAN Disconnect       Disabled              {Disabled, Enabled}
Packet Coalescing                Enabled               {Disabled, Enabled}
ARP offload for WoWLAN           Enabled               {Disabled, Enabled}
NS offload for WoWLAN            Enabled               {Disabled, Enabled}
GTK rekeying for WoWLAN          Enabled               {Disabled, Enabled}
Wake on Magic Packet             Enabled               {Disabled, Enabled}
Wake on Pattern Match            Enabled               {Disabled, Enabled}
Bluetooth(R) AMP                 Disabled              {Disabled, Enabled}
802.11n Channel Width for 2.4GHz Auto                  {20 MHz Only, Auto}
802.11n Channel Width for 5.2GHz Auto                  {20 MHz Only, Auto}
Mixed Mode Protection            RTS/CTS Enabled       {RTS/CTS Enabled, CTS-to-self Enabled}
Fat Channel Intolerant           Disabled              {Disabled, Enabled}
Transmit Power                   5. Highest            {1. Lowest, 2. Medium-low, 3. Medium, 4. Medium-High...}
HT Mode                          VHT Mode              {Disabled, HT Mode, VHT Mode}
MIMO Power Save Mode             Auto SMPS             {Auto SMPS, Static SMPS, Dynamic SMPS, No SMPS}
Roaming Aggressiveness           3. Medium             {1. Lowest, 2. Medium-low, 3. Medium, 4. Medium-High...}
Preferred Band                   3. Prefer 5.2GHz band {1. No Preference, 2. Prefer 2.4GHz band, 3. Prefer 5.2GHz band}
Throughput Booster               Disabled              {Disabled, Enabled}
U-APSD support                   Disabled              {Disabled, Enabled}
Wireless Mode                    6. 802.11a/b/g        {1. 802.11a, 2. 802.11b, 3. 802.11g, 4. 802.11b/g...}

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.

Set-NetAdapterAdvancedProperty W*i -DisplayName "Preferred Band" -DisplayValue "3. Prefer 5.2GHz band" -NoRestart
Set-NetAdapterAdvancedProperty W*i -DisplayName "Roaming Aggressiveness" -DisplayValue "3. Medium" -NoRestart
Set-NetAdapterAdvancedProperty W*i -DisplayName "Transmit Power" -DisplayValue "4. Medium-High"

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.

Note

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:

PS C:\windows\system32> Get-NetAdapter W*i | fl Dri*

DriverInformation      : Driver Date 2016-09-07 Version 19.20.0.6 NDIS 6.60
DriverFileName         : Netwtw04.sys
DriverVersion          : 19.20.0.6
DriverDate             : 2016-09-07
DriverDateData         : 131176800000000000
DriverDescription      : Intel(R) Dual Band Wireless-AC 8265
DriverMajorNdisVersion : 6
DriverMinorNdisVersion : 60
DriverName             : \SystemRoot\System32\drivers\Netwtw04.sys
DriverProvider         : Intel
DriverVersionString    : 19.20.0.6

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:

PS C:\windows\system32> Enter-PSSession -ComputerName CORPPC01
[CORPPC01]: PS> Set-NetAdapterAdvancedProperty Wi-Fi -DisplayName Roaming* -DisplayValue '3. Medium' -NoRestart
[CORPPC01]: PS> Set-NetAdapterAdvancedProperty Wi-Fi -DisplayName Preferred* -DisplayValue "1. No Preference"
WARNING: The network connection to CORPPC01 has been interrupted. Attempting to reconnect for up to 4 minutes...
WARNING: Attempting to reconnect to CORPPC01 ...
WARNING: The network connection to CORPPC01 has been restored.
[CORPPC01]: PS> Get-NetAdapterAdvancedProperty Wi-Fi -DisplayName *Band* | ft DisplayName, DisplayValue, ValidDisplayValues
DisplayName    DisplayValue     ValidDisplayValues
-----------    ------------     ------------------
Preferred Band 1. No Preference {1. No Preference, 2. Prefer 2.4GHz band, 3. Prefer 5.2GHz band}


[CORPPC01]: PS> Get-NetAdapterAdvancedProperty Wi-Fi -DisplayName *Roam* | ft DisplayName, DisplayValue, ValidDisplayValues

DisplayName            DisplayValue ValidDisplayValues
-----------            ------------ ------------------
Roaming Aggressiveness 3. Medium    {1. Lowest, 2. Medium-low, 3. Medium, 4. Medium-High...}

Here’s an example connecting to a remote machine via IP:

PS> Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.1.83"
PS> $cred = Get-Credential

PS> Enter-PSSession -ComputerName 192.168.1.83 -Credential $cred
[192.168.1.83]: PS> 

Note

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.

Appendix: Commands

Get Transmit Power value example output:

PS C:\windows\system32> Get-NetAdapterAdvancedProperty Wi-Fi -DisplayName *Transmit* | ft DisplayName, DisplayValue, ValidDisplayValues

DisplayName    DisplayValue ValidDisplayValues
-----------    ------------ ------------------
Transmit Power 5. Highest   {1. Lowest, 2. Medium-low, 3. Medium, 4. Medium-High...}

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

↑ Top