Skip to content

Instantly share code, notes, and snippets.

@imba-tjd
Created March 3, 2023 04:22
Show Gist options
  • Save imba-tjd/0eaf69c57fb8775dce298ded33ae9cb3 to your computer and use it in GitHub Desktop.
Save imba-tjd/0eaf69c57fb8775dce298ded33ae9cb3 to your computer and use it in GitHub Desktop.
Auto remove invalid Windows Firewall rules
# needs Admin privilege
# TODO: Add -confirm
$rules = Get-NetFirewallRule
foreach ($rule in $rules) {
if ($rule.Name.contains("Query User")) {
$filepath = $rule.Name.Substring($rule.Name.Indexof('}')+1)
if (-not (Test-Path $filepath)) {
echo "Removing $filepath"
Remove-NetFirewallRule -InputObject $rule
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment