I have been trying to get only specific data from the firewall rules in powershell. The command i tried is Get-NetFirewallRule | select DisplayName, Enabled, but it does not output required one.
I have been trying to get only specific data from the firewall rules in powershell. The command i tried is Get-NetFirewallRule | select DisplayName, Enabled, but it does not output required one.
Try like this (It's a bit slow):
$rules = Get-NetFirewallRule
$rules | Foreach {
$rule = (Get-NetFirewallRule -DisplayName $_.DisplayName | Get-NetFirewallPortFilter)
If($rule.Protocol -eq "TCP"){
[PSCustomObject]@{
'Rule Name' = $_.DisplayName
'TCP Port' = $rule.LocalPort
'Enabled' = $_.Enabled
}
}
}