Using PowerShell to View and Remove Wireless Profiles in Windows 10 – Part 4

Doctor Scripto

Dr Scripto

Summary: Using Windows PowerShell to purge Wlan profiles with NetSh.exe.

Last week we had a way with a Regular Expression to run one Netsh.exe command and show only the profile names as a PowerShell Array.

Today we’re going to finish the task and show you how to delete those Profiles.

As a quick reminder here’s the line in PowerShell we used to capture the list of Wireless profiles by only their names as an Array.

The resulting output containing our Wireless profile names looked like this

From our first posting we saw that to delete a WLAN profile in Netsh.exe we would execute this command.

Netsh.exe wlan delete profile PROFILENAME

Where PROFILENAME was the name of a WLAN profile such as FabrikamHotels.

So we could just purge everything with one loop like this

But I personally don’t like that. It gives me too little control, I’d rather have a function that says “show me the profiles” or even “show me only this profile”. And then I’d like the Delete to be only the information I give it (Control)

First we’ll build a function to show us the profiles, perhaps even a way to filter on them.

As part of it’s design we’ll build it as if we were building a Cmdlet as we eventually may want to add this to a Module

First thing to do is grab the list of WLAN profiles as part of our Begin.  Look closely below and you’ll see the NETSH.EXE line we ran earlier to find the profiles and show only the names.

Now we’ll rebuild that array as a PowerShell Customobject. Currently we’re only returning names, but we could build upon this later and return details of the WLAN Profiles

Now that we have the list, let’s show profiles which match the provided names in the array

However if NOTHING is provided, we will return ALL available WLAN Profiles

Now that it’s built, at least in our Script we could run this for profiles

Get-WifiProfile -name Contoso

If Contoso was there it would return as an object we could consume.

We can even provided a targeted list of WLAN Profiles

Get-WifiProfile -name Contoso, Fabrikam, DoctorScripto

It would of course try to find each one provided, and return the list as an object.

Get-WifiProfile would return everything found.

Now that we have a way to get only Specific profiles or all of them.

Next we’ll build a function in PowerShell to delete defined list of WLAN profiles. In reality we’re just wrapping PowerShell around the NETSH.exe command to simplify its use and automate it a bit more.

We could even trap for “Deleted” or “Not found to delete” conditions.

First we define the name of function. Because we’re planning in the long term to make this into a profile, I used “Get-Verb” to see a list of approved verbs. “Remove” is good to use!

We’ll step the list of provided WLAN Profile names

We will try to purge each individual one

As we trap the results, we’ll return something to indicate Success

…or failure (wasn’t there to delete)

Now we have two useful functions we can use in a script to deal with Profiles. We could even package these into a module or extend their features to allow proper piping.

But that’s a story for a different day. Meet up with us next week when we look into the Active Directory Cmdlets.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at, or post your questions on the Official Scripting Forum. See you tomorrow. Until then, peace.

Your good friend, Doctor Scripto

PowerShell, Doctor Scripto, Sean Kearney


Leave a comment