[英]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.