PowerShell Module to manage the Windows Firewall
| Command | Synopsis |
|---|---|
| Get-WindowsFirewallDynamicKeywordAddress | Gets Windows firewall dynamic keyword addresses |
| Get-WindowsFirewallEventLogTraffic | Gets audited traffic and the firewall filter that allowed or blocked it |
| Get-WindowsFirewallRule | Gets all properties of a Windows firewall rule |
| Get-WindowsFirewallRuleExpiration | Gets expiration of a temporary firewall rule |
| Get-WindowsFirewallRuleSDDLString | Generates SDDL string for use with secure firewall rule |
| New-WindowsFirewallDynamicKeywordAddress | Creates a dynamic keyword address |
| New-WindowsFirewallRule | Creates a new Windows firewall rule |
| New-WindowsFirewallTempRule | Creates a new Windows firewall temporary allow or block rule |
| Remove-WindowsFirewallDynamicKeywordAddress | Removes a dynamic keyword address |
| Set-WindowsFirewallProfile | Configures a Windows firewall profile |
| Set-WindowsFirewallRule | Applies a specified Windows firewall JSON ruleset |
| Start-WindowsFirewallAuditLogging | Enables Filtering Platform audit logging |
| Stop-WindowsFirewallAuditLogging | Restores the audit policy from before audit logging was started |
| Test-WindowsFirewallHealthProbe | Tests Windows firewall health and attempts remediation |
To apply a set of JSON-defined Windows firewall rules
> Set-WindowsFirewallRule -RuleFile FirewallRules.jsonTo apply rules that reference dynamic keyword addresses by name (see Rules\DynamicRules.json and
DynamicKeywordAddresses\DynamicKeywordAddresses.json)
> Set-WindowsFirewallRule -RuleFile DynamicRules.json -DynamicKeywordAddressFile DynamicKeywordAddresses.jsonA rule that names a dynamic keyword address not defined in these files stops the run before any rule is applied To apply rules without disabling any other rules
> Set-WindowsFirewallRule -RuleFile FirewallRules.json -AdditiveTo configure the Windows firewall profile
> Set-WindowsFirewallProfile -NetworkProfile Domain -DefaultInboundAction Block -DefaultOutboundAction AllowTo find which firewall filter is blocking traffic
> Start-WindowsFirewallAuditLogging
> # Reproduce the traffic
> Get-WindowsFirewallEventLogTraffic -Action Blocked -Port 443
> Stop-WindowsFirewallAuditLoggingInstead of a fixed Program path, a rule can set Application to find the program when the rules are
applied. If the application isn't found, WhenMissing decides whether the rule is skipped (Skip) or
fails (Fail, the default)
ExeSearch: the newestExecutableNamefound underRootDirs(default: both Program Files directories), searchingDepthlevels deep (default 5).DirectoryNamePatternoptionally filters on the name of the folder the executable is inAppxPackagewithTargetProgram:ExecutableRelativePathinside the newest installedPackageNamepackageAppxPackagewithTargetPackage: thePackageFamilyNamepackage