PowerShell Genie

Audit inbound firewall block rules

Script 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Get-NetFirewallRule is constrained by three parameters at once, returning rules that are enabled, inbound, and set to block.

The script

1PS> Get-NetFirewallRule -Enabled True -Direction Inbound -Action Block | Select-Object DisplayName,Profile,Direction,Action

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 DisplayName Profile Direction Action
    2 ----------- ------- --------- ------
    3 Sample object Domain Inbound Block
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-NetFirewallRule -Enabled True -Direction Inbound -Action Block | Select-Object DisplayName,Profile,Direction,Action
    1. Stage 1Get-NetFirewallRule-Enabled -Direction -Action
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Get-NetFirewallRule is constrained by three parameters at once, returning rules that are enabled, inbound, and set to block. The projection reports the display name with the profiles the rule applies to alongside its direction and action.

      Adapting it

      Pipe the results into Get-NetFirewallPortFilter to attach the ports each rule actually covers, because a rule display name rarely reveals what it blocks.

      If the result is unexpected

      An inbound-block report fails to explain which firewall rule applies.

      Rule state, profile, direction and associated port or address filters must be interpreted together.

      1. Inspect the active profile and the matching rule's port, address and application filters.

      Validate the result

      The candidate rule matches the affected connection's direction and endpoints.

      Keep the check reliable

      Keep rule identifiers and associated filters together in exports.

      Primary documentation

      Windows services and processes documentation

      Continue
      Genie guideAudit inbound firewall block rules

      Get-NetFirewallRule is constrained by three parameters at once, returning rules that are enabled, inbound, and set to block.