The really important thing about our firewall is the rules that are configured.
function get-rule { [CmdletBinding()] param () BEGIN{}#begin PROCESS{ $fw = New-Object -ComObject HNetCfg.FwPolicy2 $fw.Rules | foreach { $profiles = @() $ruleprofile = $_.Profiles @(1,2,4, 1073741824) | foreach { if ($_ -band $ruleprofile){$profiles += [ProfileType]($_)} } $rule = New-Object -TypeName PSObject -Property @{ Name = $_.Name Protocol = [Protocol]($_.Protocol) Direction = [Direction]($_.Direction) Profile = $profiles Action = [Action]($_.Action) } $rule.PSTypeNames[0] = "FirewallRule" $rule } }#process END{}#end <# .SYNOPSIS Displays firewall rules .DESCRIPTION Displays firewall rules. Properties are: Name Protocol Direction Profile Action .EXAMPLE get-rule get-rule | format-table -AutoSize -Wrap #> }
Start with the HNetCfg.FwPolicy2 object. Put the Rules collection onto the pipeline. check each of the possible profiles and add them to the array.
An output object is created with the properties converted from their numeric values to descriptive values using a few more enumerations.
Suggested usage:
get-rule
get-rule | format-table -AutoSize -Wrap