A
A
Alexander Semenenko2020-01-14 11:29:51
PowerShell
Alexander Semenenko, 2020-01-14 11:29:51

How to get a firewall rule for a specific port from powershell?

The difficulty is that I can pull out the rule for example by DisplayName:

Get-NetFirewallRule -DisplayName Имя_правила
Name                  : {3b28deef-8069-4492-a75a-913f2e818f30}
DisplayName           : Имя_правила
Description           :
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Any
Platform              : {}
Direction             : Outbound
Action                : Block
EdgeTraversalPolicy   : Block
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : Правило было успешно проанализировано из хранилища. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Well, or for any of the above parameters, but how to display a rule for RemotePort? Whether I need to learn from PowerShell or cmd there is a rule for the given tcp port.
I found this design on the internet:
Get-NetFirewallRule -Action Block -Enabled True -Direction Outbound |
Format-Table -Property DisplayName,
@{Name='Protocol';Expression={($PSItem | Get-NetFirewallPortFilter).Protocol}},
@{Name='LocalPort';Expression={($PSItem | Get-NetFirewallPortFilter).LocalPort}},
@{Name='RemotePort';Expression={($PSItem | Get-NetFirewallPortFilter).RemotePort}},
@{Name='RemoteAddress';Expression={($PSItem | Get-NetFirewallAddressFilter).RemoteAddress}},
Enabled,Profile,Direction,Action

Ports shows, but I need to display only one rule, not all. Tried to add |fl *port*, but it doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2020-01-14
@semenenko88

and so?

Get-NetFirewallPortFilter | where RemotePort -eq 554 | select InstanceID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question