Skip to content

Instantly share code, notes, and snippets.

@AgentRev
Created December 22, 2020 10:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AgentRev/a4f93dcca1dc27c72963b36f3b345820 to your computer and use it in GitHub Desktop.
Save AgentRev/a4f93dcca1dc27c72963b36f3b345820 to your computer and use it in GitHub Desktop.
Removes orphaned entries from the Windows Firewall.
#
# firewall_cleanup.ps1
#
# Removes orphaned entries from the Windows Firewall.
#
$rules = Get-NetFirewallApplicationFilter | Where {($_.Program -ne "Any") -and ($_.Program -ne "System") -and (-not (Test-Path ([Environment]::ExpandEnvironmentVariables($_.Program))))} | Get-NetFirewallRule
foreach ($rule in $rules)
{
Write-Host "REMOVING RULE:" $rule.Direction "-" $rule.DisplayName
Remove-NetFirewallRule -InputObject $rule #-WhatIf
}
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment