When creating Windows Firewall rule with New-NetFirewallRule
, it returns some data about rule created:
PS C:> New-NetFirewallRule -DisplayName "Allow debug rule" -Direction inbound -Profile Any -Action Allow -LocalPort 3333 -Protocol UDP -RemoteAddress 127.0.0.2
Name : {2326a022-ec7d-495e-80c0-636ec5f615b9}
DisplayName : Allow debug rule
Description :
DisplayGroup :
Group :
Enabled : True
Profile : Any
Platform : {}
Direction : Inbound
Action : Allow
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : The rule was parsed successfully from the store. (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
I could select
from this returned data and get some fields values (e.g. Name, DisplayName, Action, Direction
), but can’t get LocalPort
value since it is not returned.
How could I get LocalPort
value for the new rule just created with New-NetFirewallRule
?