【发布时间】:2021-02-23 14:19:36
【问题描述】:
我需要在 powershell 中解析 netsh 命令给出的输出。 以下是我正在使用的命令
Netsh advfirewall show private
证明下面的输出
Private Profile Settings:
----------------------------------------------------------------------
State ON
Firewall Policy BlockInbound,AllowOutbound
LocalFirewallRules N/A (GPO-store only)
LocalConSecRules N/A (GPO-store only)
InboundUserNotification Enable
RemoteManagement Disable
UnicastResponseToMulticast Enable
Logging:
LogAllowedConnections Disable
LogDroppedConnections Disable
FileName %systemroot%\system32\LogFiles\Firewall\pfirewall.log
MaxFileSize 4096
我的要求是访问上述输出中的每个值。类似 $result.state / $result.InboundUserNotification
我对 PowerShell 还是很陌生,我在 google 上搜索过这方面的内容,但没有找到任何东西。
【问题讨论】:
-
您是否尝试过使用“Get-NetFirewallProfile Private”?这在所有当前的 Windows 版本中都可以做到。
-
我试过这个。但是 Get-NetFirewallProfile 存在问题。你可以参考这个linkNetsh 正在给我本地计算机上的当前设置
-
我不知道这个特定的 cmdlet,但总的来说
netsh被认为已弃用,如果发生冲突,应该首选 powershell cmdlet。
标签: windows powershell parsing