PowerShell Genie

NetSecurity module: setup and commands

Module 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Inspect Windows Firewall profiles and rules with Get-NetFirewallProfile and Get-NetFirewallRule before changing direction, scope or enforcement.

Getting it

Included with Windows 8 and Windows Server 2012 onward. Windows only.

Examples

1PS> Get-NetFirewallProfile
Show reference output
1 Name Enabled DefaultInboundAction DefaultOutboundAction
2 ---- ------- -------------------- ---------------------
3 Domain True Block Allow
4 Private True Block Allow
5 Public True Block Allow
1PS> Get-NetFirewallRule -Enabled True
Show reference output
1 Name DisplayName Enabled Direction Action
2 ---- ----------- ------- --------- ------
3 PSG-HTTPS-In HTTPS inbound True Inbound Allow

What it is for

Use it to prove which profile is active and which rules are enabled on a host under investigation. It is also the supported way to create a rule from automation instead of clicking through the firewall console on each server.

Typical tasks

  • Confirm firewall state for each profile
  • List enabled inbound rules with their actions
  • Trace a rule back to its port filter
  • Create a scoped rule for one application
  • Find rules that allow any remote address
  • Export the rule set for a compliance record

Check the installed version

1PS> Get-Module -ListAvailable NetSecurity | Select-Object Name, Version, Path
2PS> Get-Command -Module NetSecurity

Compare the module path and version with the session used by your scheduled task or automation account. Use it to prove which profile is active and which rules are enabled on a host under investigation. It is also the supported way to create a rule from automation instead of clicking through the firewall console on each server.

Primary documentation

PowerShell objects and pipelines documentation

Continue
Genie guideNetSecurity module: setup and commands

Inspect Windows Firewall profiles and rules with Get-NetFirewallProfile and Get-NetFirewallRule before changing direction, scope or enforcement.