繁体   English   中英

使用powerhsell导出从GPO应用的防火墙规则

[英]Export firewall rules applied from GPO using powerhsell

我正在使用下面的代码将本地应用的防火墙规则导出到.csv。

$Rules=(New-object –comObject HNetCfg.FwPolicy2).rules
$Rules | export-csv test.csv -NoTypeInformation

该脚本不会导出通过GPO应用的fw规则。 如何获得GPO应用的规则进行导出?

在Win8 / Server2012及更高版本上:

Get-NetFirewallRule -PolicyStore RSOP

在较旧的系统上,您可以解析gpresult或RSOP xml。 例如,对于入站规则:

$xmlpath = "C:\example.xml"
& gpresult.exe /x C:\example.xml
$xml = [xml](Get-Content $xmlpath)
($xml.DocumentElement.ComputerResults.ExtensionData.extension | 
    ? {$_.type -like "*firewall*"}).inboundfirewallrules | Export-Csv test.csv -NoTypeInformation

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM