Advertisement
guyrleech

Show Windows Firewall Rules for Programs

Oct 9th, 2024
1,294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 0.66 KB | Cybersecurity | 0 0
  1. ## Get all Windows Firewall rules that specify a program and show those which are inbound and enabled
  2.  
  3. ## Cache rules and ports for cross referencing
  4. $allrules = Get-NetFirewallRule
  5. $allports = Get-NetFirewallPortFilter
  6.  
  7. # pipe through sort -property your_choice_of_property
  8. Get-NetFirewallApplicationFilter |select @{n='Program';e={$_.Program}},@{n='Rule';e={$allrules|Where Name -ieq $_.InstanceID}}|where { $_.rule.Enabled -eq 'true' -and $_.rule.Direction -ieq 'inbound'} |select Program,@{n='Rule';e={$_.rule.displayname}},@{n='Ports';e={$script:port = $allports|where InstanceID -eq $_.rule.Name;$script:port.Localport}},@{n='Protocol';e={$script:port.protocol}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement