Skip to content

Instantly share code, notes, and snippets.

@xbb
Last active January 31, 2023 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xbb/246529a0c91305d53d428e116249c4ba to your computer and use it in GitHub Desktop.
Save xbb/246529a0c91305d53d428e116249c4ba to your computer and use it in GitHub Desktop.
Removes Windows Firewall program rules pointing to non-existing paths
# Usage: windows-firewall-cleanup.ps1 [-y]
# use -y parameter to actually remove the rules
param(
[switch]$y = $false
)
Get-NetFirewallApplicationFilter | ForEach-Object {
$program = $_.Program
if ([System.IO.Path]::IsPathRooted($program)) {
if (!(Test-Path -Path "$program" -PathType Leaf)) {
Write-Output "Removing: $program"
if ($y) {
$_ | Remove-NetFirewallRule
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment