ConfigMgr PowerShell

Change the Preferred Band Setting for a Wireless Network Adapter Using a CI/Baseline

August 27, 2020

Hello Readers! My name is Curt Ricard and I am a Customer Engineer (i.e. PFE/DSE – we were recently rebranded) working with Config Manager.


One of my New Fiscal Year Resolutions is to blog on this site with my colleague & friend, Ken, who started this site. I hope I occasionally save you a bit of work, help you leverage existing and new Config Manager features, and make you laugh….and hopefully, the laughter will not be directed at my code.

And Now a Word From Our Lawyers:

Anything I post here is my own opinion, and my past, current, and future employer makes no guarantees about any code samples included here. Use at your own risk.

Now, let’s get started…

Background:
Most wireless adapters can run in 2.4 GHz or 5 GHz frequencies (sometimes called “Bands”) in Windows. Surprisingly, I had never changed this setting on any device I’ve owned, leased, rented, or built. On the Intel® adapters, this setting is referred to as Preferred Band.

I decided to blog about this because I wasn’t able to borrow code from anyone else to complete this task, which made me think that someone else could benefit from my work.

If you have an Intel® wireless adapter, try viewing this setting in Device Manager. Just select the wireless adapter, view its properties, and then select the Advanced tab:


The Problem: To resolve an issue with specific wireless access points, a networking team asked if Config Manager could be used to modify the Preferred Band setting for the Intel® Wireless network adapters on a collection of Windows 10 clients. We were directed to set the Preferred Band value to 5GHz.

The solution: We decided to use a PowerShell script, deployed by a CI/Baseline, to modify this setting.

During testing, we discovered that some adapters had a desired value of 3. Prefer 5GHz band, while others read 3. Prefer 5.2GHz band, and so forth. This meant the script had to do a partial text match when interpreting the status of the current Preferred Band value, and when resetting it.

This resulted in the detection & remediation scripts below. Thank you for reading!

Detection script

<# This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. 
 THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING 
 BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.  
#>
###Detection script###
# must be laptop; https://lintnotes.com/updated-win32_systemenclosure-chassis-types/
# must have wifi adapter; https://www.powershellmagazine.com/2013/04/04/pstip-detecting-wi-fi-adapters/
# must have Intel adapter; 

$strCompliant = $false

$chassis = Get-WmiObject win32_systemenclosure -computer $env:COMPUTERNAME | select chassistypes

#"9", "10","11", "12", "14","18","21","30","31","32" #these are laptop chassis types.  See https://lintnotes.com/updated-win32_systemenclosure-chassis-types/


$laptop = switch ( $chassis.chassistypes ) {
        '9'  { 'True' }
        '10' { 'True' }
        '11' { 'True' }
        '12' { 'True' }
        '14' { 'True' }
        '18' { 'True' }
        '21' { 'True' }
        '30' { 'True' }
        '31' { 'True' }
        '32' { 'True' }
        Default {'False'} 
    } #Ends Switch statement


#for testing - comment out the switch statement and enable this
#$laptop = "True"

If ($laptop -ne "True"){
        $strCompliant = $True #This is not a laptop, no need to run remediation
        }
Else {
            #Verify wifi adapter
                      
                $a = Get-NetAdapter -InterfaceDescription '*Intel*' -Physical
               
                $IntDist = $a[0].InterfaceDescription 

                $c = Select-String -Pattern "Intel" -InputObject $IntDist

             If ($C) {$PreferredBand = Get-NetAdapterAdvancedProperty W*i -DisplayName "Preferred Band" |  foreach {$currentValue = $_.DisplayValue}
                } #Ends Nested If
                Else {
                $strCompliant = $true}
            } #Ends If/Else

            If ($currentValue -Match "Prefer 5*"){
                 $strCompliant = $true

            }#Ends If
    
 #} #Ends If/Else
write-output $strCompliant

Remediation Script

###Remediation Script###
#get valid display values
$PreferredBand2= Get-NetAdapterAdvancedProperty W*i -DisplayName "Preferred Band" |  foreach {$ValidValues = $_.ValidDisplayValues}

foreach ($entry in $ValidValues){
    #write-host "entry:" $entry
    #find an entry that matches our text pattern & set the $NewValue variable.
    If ($entry -match "Prefer 5"){$NewValue = $entry}
    #write-host "newval:" $NewValue
    Set-NetAdapterAdvancedProperty W*i -DisplayName "Preferred Band" -DisplayValue "$NewValue" -NoRestart
    } #closes foreach loop