{"id":420,"date":"2021-10-14T10:58:16","date_gmt":"2021-10-14T14:58:16","guid":{"rendered":"https:\/\/wangxiaohu.com\/blog\/?p=420"},"modified":"2021-10-14T11:03:03","modified_gmt":"2021-10-14T15:03:03","slug":"clean-unused-firewall-rules-using-powershell","status":"publish","type":"post","link":"https:\/\/wangxiaohu.com\/blog\/?p=420","title":{"rendered":"Clean unused firewall rules using PowerShell"},"content":{"rendered":"\n<p>In Windows, firewall rules can be easily cumulated over time. Every time a new application is launched, the user will be prompted to create a new firewall rule for the app. However, when applications get uninstalled, most of them would not remove the firewall rule it has created.<\/p>\n\n\n\n<p>Once there are more than just a few unused firewall rules, the system becomes less secure due to the exposed protocols and ports. A mocked application at the exact same file path can easily take advantage of existing firewall rules created and make the system vulnerable.<\/p>\n\n\n\n<p>Unused firewall rules can be cleaned up with just 3 lines of PowerShell commands, under elevated command prompt:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$unusedFilters = Get-NetFirewallApplicationFilter | Where-Object {$_.Program -notin (\"Any\", \"System\")} | Where-Object {-not (Test-Path (&#91;System.Environment]::ExpandEnvironmentVariables($_.Program)))}\n\n$unusedRules = Get-NetFirewallRule | Where-Object {$_.Name -in $unusedFilters.InstanceId}\n\n$unusedRules | Remove-NetFirewallRule -Verbose<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/i0.wp.com\/wangxiaohu.com\/blog\/wp-content\/uploads\/2021\/10\/image.png?ssl=1\"><img loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"251\" src=\"https:\/\/i0.wp.com\/wangxiaohu.com\/blog\/wp-content\/uploads\/2021\/10\/image.png?resize=660%2C251&#038;ssl=1\" alt=\"\" class=\"wp-image-422\" srcset=\"https:\/\/i0.wp.com\/wangxiaohu.com\/blog\/wp-content\/uploads\/2021\/10\/image.png?resize=1024%2C389&amp;ssl=1 1024w, https:\/\/i0.wp.com\/wangxiaohu.com\/blog\/wp-content\/uploads\/2021\/10\/image.png?resize=300%2C114&amp;ssl=1 300w, https:\/\/i0.wp.com\/wangxiaohu.com\/blog\/wp-content\/uploads\/2021\/10\/image.png?resize=768%2C292&amp;ssl=1 768w, https:\/\/i0.wp.com\/wangxiaohu.com\/blog\/wp-content\/uploads\/2021\/10\/image.png?resize=1536%2C584&amp;ssl=1 1536w, https:\/\/i0.wp.com\/wangxiaohu.com\/blog\/wp-content\/uploads\/2021\/10\/image.png?w=1575&amp;ssl=1 1575w, https:\/\/i0.wp.com\/wangxiaohu.com\/blog\/wp-content\/uploads\/2021\/10\/image.png?w=1320&amp;ssl=1 1320w\" sizes=\"(max-width: 660px) 100vw, 660px\" data-recalc-dims=\"1\" \/><\/a><figcaption>PSPrompt customized using <a rel=\"noreferrer noopener\" href=\"https:\/\/ohmyposh.dev\/\" target=\"_blank\">oh-my-posh<\/a><\/figcaption><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Windows, firewall rules can be easily cumulated over &hellip; <a href=\"https:\/\/wangxiaohu.com\/blog\/?p=420\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Clean unused firewall rules using PowerShell<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_jetpack_memberships_contains_paid_content":false},"categories":[1],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pdhZ2A-6M","_links":{"self":[{"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/420"}],"collection":[{"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=420"}],"version-history":[{"count":5,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/420\/revisions"}],"predecessor-version":[{"id":426,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/420\/revisions\/426"}],"wp:attachment":[{"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangxiaohu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}