Last active
September 9, 2024 19:44
-
-
Save xbb/246529a0c91305d53d428e116249c4ba to your computer and use it in GitHub Desktop.
Removes Windows Firewall program rules pointing to non-existing paths
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
# 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