Hi I need to query FW GPO ports within multiple remote servers. At the first step I build this query which should retrieve the information locally and I plan to add it as a .PS script inside ScriptBlock. I built a query that integrates results from two different queries. On the first query, I put the filters I need without any issues however on the second query I had issues.
This is the script:
Get-NetFirewallRule -Action Allow -Enabled True -Direction Inbound | Select-Object -Unique | Where-Object {$_.LocalPort -eq 7680}|
Format-Table -Property Profile,
Enabled,
Direction,
@{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}},
Profile
I have a couple of questions:
- Can someone advise how to filter local ports and also a range of ports in this query? I tried many times without success (how do we use
Where-Object
to query such as that@{Name='Protocol';Expression={($PSItem | Get-NetFirewallPortFilter).Protocol}}
) - Will use
netsh
instead will it be preferable? - How do we customize the results and present the results in AsBuiltReport framework?
Thanks Shai
I tried to modify the where-object with no success. It should bring back the rows where
Action=Allow,
Enabled=True
Direction=Inbound
and
($_.LocalPort -match '80|135|139|445|5985|5986' -or $_.LocalPort -ge 49152 -or $_.LocalPort -le 65535)