英文:
discovery if ICMPv4 inbound is allowed on firewall
问题
尝试列出 Windows 防火墙上允许的 ICMPv4 入站规则(以便在批处理/PowerShell混合脚本中处理)
powershell.exe "Get-NetFirewallPortFilter -Protocol icmpv4 | Get-NetFirewallRule | ft enabled,direction,action"
这会给我大约10个结果。如何仅筛选具有 "Enabled=True" 和 "Direction=Inbound" 的结果?我可以使用 findstr 来筛选脚本输出,但最好在 PowerShell 中完成这个任务。
英文:
Trying to list ICMPv4 Inbound Allowed rule on windows firewall (to process in batch/ps hybrid script)
powershell.exe "Get-NetFirewallPortFilter -Protocol icmpv4 | Get-NetFirewallRule | ft enabled,direction,action"
This give me about 10 results. How to filter only results which have "Enabled=True" and "Direction=Inbound"? I am able filter script output by findstr, but shoud be better to do this in powershell.
答案1
得分: 1
你应该使用 Where-Object
:
powershell.exe "Get-NetFirewallPortFilter -Protocol icmpv4 | Get-NetFirewallRule | Where-Object {`$_.Enabled -eq 'True' -and `$_.Direction -eq 'Inbound'} | ft enabled,direction,action"
英文:
You should use Where-Object
:
powershell.exe "Get-NetFirewallPortFilter -Protocol icmpv4 | Get-NetFirewallRule | Where-Object {`$_.Enabled -eq 'True' -and `$_.Direction -eq 'Inbound'} | ft enabled,direction,action"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论