簡體   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