Created
February 2, 2014 23:51
-
-
Save aaronpowell/8776893 to your computer and use it in GitHub Desktop.
Delete wifi profiles in Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $_ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recommend you replace $host.ui.PromptForChoice(...) with [CmdletBinding(SupportsShouldProcess)] and $PSCmdlet.ShouldProcess(...).
http://technet.microsoft.com/en-us/library/hh847781.aspx