Created
March 3, 2023 04:22
-
-
Save imba-tjd/0eaf69c57fb8775dce298ded33ae9cb3 to your computer and use it in GitHub Desktop.
Auto remove invalid Windows Firewall rules
This file contains hidden or 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
# 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