Using Windows PowerShell to Cleanup your Wireless Profiles


One of the cooler features with Windows 8 and 8.1 is the ability to let your settings roam from Device to device. A perfect example of this is your wireless profiles.

Earlier versions of Windows settings for the Wireless configuration were maintained upon each individual computer. The drawback to this of course would be that if I had a new computer, the settings for any Wireless networks would need to be re-configured again each time.

When we sign into Windows 8 and Windows 8.1 with a Microsoft ID (such as Hotmail.com or Live.com) those settings can now float from one computer to the next. This is amazing convenient when I start up on a brand new computer.

I however have stumbled into an interesting challenge. Since my computer now can remember all of these old networks, the list can get rather cluttered and large over time.

For a regular Home user this is not a problem, but for those with a Tablet device roaming from location to location it can be. There are times you may encounter new Wireless networks with the same SSID as previous ones. Generic names such are “wireless” or default vendor names are not uncommon choices.

In my own particular laptop I had a problem which required me to clean out some Wireless profiles. Without Windows PowerShell you can find this out using the NETSH command

NETSH WLAN SHOW PROFILE

This will produce a large list on your screen that may look something similar to this.

clip_image002

In the case of my laptop I found over thirty seven (37) profiles from clients, conferences, my home and even my former employer.

If you need to remove one of these profiles you have two methods to work from. In Windows 8.1 you can choose to access the GUI under Settings/Change PC Settings/Network/Connections and click on “Manage known networks”

clip_image004

Clicking on “Manage known networks” will yield the list of Wireless networks in your laptop configuration. At this point you can click on a name and select the “Forget” button to remove it from your list of wireless profiles.

clip_image006

You can also do this from the command prompt using the NETSH command in this fashion.

NETSH WLAN DELETE PROFILE NAME=”Eot-Secondary”

This would delete the Wireless network named Eot-Secondary

The problem we have is trying to delete multiple wireless networks. With both the GUI and the NETSH solution it’s still a pretty manual process. Manually select and Network and click “Forget” or Manually type in the Wireless SSID name to remove it using NETSH.

Yet somewhere in the distance I sense a solution using Windows PowerShell. At the VERY least we can build a function to pass the SSID to the NETSH command line. With this in place you could have a CSV file of SSID names to purge them

This is quite easy with a simple function like this

Function Remove-WIFIProfile($SSID)

{

(NETSH WLAN DELETE PROFILE NAME=$SSID)

}

What can now do is clean out old Wireless profiles in this simple format

Remove-WIFIProfile –SSID Eot-Secondary

This is all well and fine but what about that big list the computer has? Is there some way to make that useful?

Ahem…. Windows PowerShell can help there as well. Let’s capture the output from the NETSH command to list the wireless profiles first.

$SSIDList=(NETSH WLAN SHOW PROFILE) | Select-String ‘All User Profile’

Now we only have the output which contains the lines with the Wireless SSIDs. We can take this output and build a CSV file to store the information.

The first thing we’ll do format the output into something we can output directly to a csv.

$SSIDList | Foreach { [pscustomobject]@{SSID=$_.line.substring(27) }}

We can visually verify the output first.

clip_image008

With an EXPORT-CSV added on, we can store this output away into something we can use later.

$SSIDList | Foreach { [pscustomobject]@{SSID=$_.line.substring(27) }} | Export-Csv C:\data\wifi.csv –NoTypeInformation

At this point you’ll have a list of all of your wireless profiles which you can sort through and clean with Excel (or Notepad if you are so daring!).

We can then take this cleaned up list and clean up old profiles with our earlier function in this fashion.

Import-Csv C:\data\wifi.csv | Foreach { Remove-WifiProfile –ssid $_.SSID }

You can now proudly smile at your much cleaner list of wireless profiles and a just well done thanks to Windows PowerShell.

Sean

Remember the Power of Shell is in YOU

Follow

Get every new post delivered to your Inbox.

Join 2,955 other followers