Skip to content

Instantly share code, notes, and snippets.

@aaronpowell
Created February 2, 2014 23:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronpowell/8776893 to your computer and use it in GitHub Desktop.
Save aaronpowell/8776893 to your computer and use it in GitHub Desktop.
Delete wifi profiles in Windows
function PromptForRemoval {
param (
[string]
[Parameter(Mandatory=$true)]
$Networkname
)
$title = "Delete network $NetworkName"
$message = "Do you want to delete the wifi network named $NetworkName"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Delete network."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"Keep network."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
if ($result -eq 1) {
return
}
netsh wlan delete profile name="$NetworkName"
}
$networks = netsh wlan show profiles | %{ $_.Split(':')[1] }
$networks = $networks | where { $_ -ne $null -and $_ -ne "" } | %{ $_.Trim() }
$networks | %{ PromptForRemoval -NetworkName $_ }
@jstangroome
Copy link

I recommend you replace $host.ui.PromptForChoice(...) with [CmdletBinding(SupportsShouldProcess)] and $PSCmdlet.ShouldProcess(...).
http://technet.microsoft.com/en-us/library/hh847781.aspx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment