使用PowerShell v2导出防火墙规则以实现卓越
我正在尝试在Excel表格中整合下面的命令的输出
netsh advfirewall firewall show rule name = all | out-file .\rules.txt
目前上面的命令的输出看起来像这样
Rule Name: Remote Assistance (PNRP-Out) ---------------------------------------------------------------------- Enabled: Yes Direction: Out Profiles: Domain,Private Grouping: Remote Assistance LocalIP: Any RemoteIP: Any Protocol: UDP LocalPort: Any RemotePort: Any Edge traversal: No Action: Allow
我需要有这样的excel文件
Rule Name Enabled Direction Profiles Grouping LocalIP RemoteIP Protocol RemotePort Edge Transversal Actions Remote Assistance (PNRP-Out) Yes Out Domain,Private Remote Assistance Any Any UDP Any No Allow
有没有办法做到这一点。 这只能在poweshell v2上完成。 没有其他模块可以导入。 这应该为netsh命令输出的每个规则完成。
提前谢谢你!
你可以使用com对象获取规则并转换为csv(csv可以用excel打开),如下所示:
$Rules=(New-object –comObject HNetCfg.FwPolicy2).rules $Rules | export-csv test.csv -NoTypeInformation